Solved

extern static

Posted on 2002-04-10
2
241 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 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

14 Experts available now in Live!

Get 1:1 Help Now