Solved

extern static

Posted on 2002-04-10
2
248 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 50 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

729 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