Solved

extern static

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Load and store *.pnm image file 1 75
Need some help with listview limit text 20 97
Getting IP address 8 71
ASP.net build a IF/Then Walkthrough Guide 1 189
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now