Solved

extern static

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

808 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