Click here to Skip to main content
16,004,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: extern? Pin
Chris Losinger5-Jan-02 4:14
professionalChris Losinger5-Jan-02 4:14 
GeneralRe: extern? Pin
Stan the man5-Jan-02 4:19
Stan the man5-Jan-02 4:19 
GeneralRe: extern? Pin
Chris Losinger5-Jan-02 4:24
professionalChris Losinger5-Jan-02 4:24 
AnswerRe: extern? Pin
Rick York5-Jan-02 6:48
mveRick York5-Jan-02 6:48 
AnswerRe: extern? Pin
Christian Graus5-Jan-02 9:32
protectorChristian Graus5-Jan-02 9:32 
GeneralRe: extern? Pin
Tim Smith5-Jan-02 11:01
Tim Smith5-Jan-02 11:01 
GeneralRe: extern? Pin
Christian Graus5-Jan-02 11:08
protectorChristian Graus5-Jan-02 11:08 
AnswerRe: extern? Pin
David Chamberlain7-Jan-02 7:56
David Chamberlain7-Jan-02 7:56 
As a very "general" rule, you should try to avoid declaring variables in a header file, simply because every source file that includes them will re-create that variable's declaration. If you really want a global variable, you should declare it in a source file, and then when another source file needs to access or update it, declare it again in that source file using extern. Extern says "There is a variable (with memory allocated) somewhere else in the program and it looks like this." Separating your global variables like this helps to keep track of them, because you declare them in the source file where they are "owned," and then use extern for everywhere else where they are "used."

While various macros have been developed for use in header files to optionally compile or not compile the extern for variables, this is really just a confusing trick to get the compiler to do what I have described. It's only confusing to you and other programmers, because you still have to find when the original file is to find if the macro #define is made in order to get the original variable declaration.

Dave

"You can say that again." -- Department of Redundancy Department
GeneralTabbed multiple views Pin
Nnamdi Onyeyiri5-Jan-02 3:26
Nnamdi Onyeyiri5-Jan-02 3:26 
QuestionHow to write a service by VC Pin
Vistac5-Jan-02 3:10
Vistac5-Jan-02 3:10 
AnswerRe: How to write a service by VC Pin
Chris Losinger5-Jan-02 3:25
professionalChris Losinger5-Jan-02 3:25 
GeneralDoc/View Application Pin
5-Jan-02 2:59
suss5-Jan-02 2:59 
GeneralRe: Doc/View Application Pin
Eugene Pustovoyt5-Jan-02 4:21
Eugene Pustovoyt5-Jan-02 4:21 
GeneralRe: Doc/View Application Pin
5-Jan-02 5:13
suss5-Jan-02 5:13 
GeneralRe: Doc/View Application Pin
5-Jan-02 11:13
suss5-Jan-02 11:13 
GeneralRe: Doc/View Application Pin
6-Jan-02 2:41
suss6-Jan-02 2:41 
General.dib file Pin
Neha5-Jan-02 0:17
Neha5-Jan-02 0:17 
GeneralRe: .dib file Pin
Philip Patrick5-Jan-02 0:23
professionalPhilip Patrick5-Jan-02 0:23 
GeneralRe: .dib file Pin
Neha5-Jan-02 0:33
Neha5-Jan-02 0:33 
GeneralRe: .dib file Pin
Philip Patrick5-Jan-02 0:43
professionalPhilip Patrick5-Jan-02 0:43 
GeneralRe: .dib file Pin
Neha5-Jan-02 1:06
Neha5-Jan-02 1:06 
GeneralRe: .dib file Pin
Philip Patrick5-Jan-02 1:27
professionalPhilip Patrick5-Jan-02 1:27 
GeneralRe: .dib file Pin
Philip Patrick5-Jan-02 1:40
professionalPhilip Patrick5-Jan-02 1:40 
QuestionWhat infected the exe ? Pin
ColinDavies4-Jan-02 20:11
ColinDavies4-Jan-02 20:11 
AnswerRe: What infected the exe ? Pin
Philip Patrick5-Jan-02 1:53
professionalPhilip Patrick5-Jan-02 1:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.