?
Solved

extern static

Posted on 2002-04-10
2
Medium Priority
?
249 Views
Last Modified: 2006-11-17
Could some one explain me the significance of extern static variable. Also a situation when i would use this.

Thanks
ilikenine
0
Comment
Question by:ilikenine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
makerp earned 200 total points
ID: 6931523
errrr,

well extern says to the compiler that a variable exists in another place (not the file it is extern'ed in, the linker will resolve this)

static says that the variable is local to the file it is in a can not be seen outside the file (obj), i.e. you should not be able to extern to a variable declared like:

static int va1

so your statment appears to say that the externaly referenced variable can only be seen in the file the statement is in (static can also mean other things in classes etc). this i suppose makes sense, although extern implies static in this context.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6932088
Using static for file scope is depricated.

static int va1; //Depricated

Instead do the following:

namespace
{
int val;
}

This is the correct method for new code.

you can still use static keyword for function scope.

void MyFunction(void)
{
static int val;//Not depricated
}
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question