Click here to Skip to main content
15,894,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to check if an internet connection exist ? Pin
_Flaviu24-Jan-12 1:13
_Flaviu24-Jan-12 1:13 
AnswerRe: How to check if an internet connection exist ? Pin
Rajesh R Subramanian24-Jan-12 2:07
professionalRajesh R Subramanian24-Jan-12 2:07 
Questionusing extern in C Pin
Sakhalean23-Jan-12 22:53
Sakhalean23-Jan-12 22:53 
AnswerRe: using extern in C Pin
Jochen Arndt23-Jan-12 23:09
professionalJochen Arndt23-Jan-12 23:09 
GeneralRe: using extern in C Pin
Sakhalean23-Jan-12 23:32
Sakhalean23-Jan-12 23:32 
GeneralRe: using extern in C Pin
Jochen Arndt23-Jan-12 23:41
professionalJochen Arndt23-Jan-12 23:41 
AnswerRe: using extern in C Pin
Erudite_Eric24-Jan-12 5:33
Erudite_Eric24-Jan-12 5:33 
AnswerRe: using extern in C Pin
Stefan_Lang24-Jan-12 5:50
Stefan_Lang24-Jan-12 5:50 
Your question shows that you don't understand scope.

When you declare a variable using extern, it has global scope. Global scope means that all parts of your application will access the same variable when using that name, and there's only one variable and one value.

When you declare a variable in your .c file, but not elsewhere, this variable has local scope. Local scope means you can use it in this compilation unit only, and only from the point where you declare it, not before. It also means that when you use the same name in another .c file you get a compiler error, because the variable is not known there. You can declare another variable by the same name in another .c file. If you do that, that variable will be independent of the first one - you will have two different variables storing two different values.

If you want a variable that does not affect other parts of your application when you change it, you need a local variable

On a sidenote, it is a good practice to avoid variables with global scope. Prefer local variables over global ones wherever you can. Instead of using global variables, pass every value that a function requires as a fucntion argument, even if the only thing the function does with it is pass it on to another function.
GeneralRe: using extern in C Pin
Erudite_Eric24-Jan-12 6:23
Erudite_Eric24-Jan-12 6:23 
GeneralRe: using extern in C Pin
Stefan_Lang24-Jan-12 22:44
Stefan_Lang24-Jan-12 22:44 
GeneralRe: using extern in C Pin
Erudite_Eric25-Jan-12 0:32
Erudite_Eric25-Jan-12 0:32 
AnswerRe: using extern in C Pin
«_Superman_»24-Jan-12 15:37
professional«_Superman_»24-Jan-12 15:37 
JokeRe: using extern in C Pin
Peter_in_278024-Jan-12 15:58
professionalPeter_in_278024-Jan-12 15:58 
GeneralRe: using extern in C Pin
Mohibur Rashid24-Jan-12 22:46
professionalMohibur Rashid24-Jan-12 22:46 
QuestionPlaying .wav file Pin
D.Manivelan23-Jan-12 19:33
D.Manivelan23-Jan-12 19:33 
AnswerRe: Playing .wav file Pin
PJ Arends23-Jan-12 19:49
professionalPJ Arends23-Jan-12 19:49 
GeneralRe: Playing .wav file Pin
D.Manivelan23-Jan-12 20:11
D.Manivelan23-Jan-12 20:11 
QuestionCustom drawn button inside the onInitDialog Pin
sdancer7523-Jan-12 8:47
sdancer7523-Jan-12 8:47 
AnswerRe: Custom drawn button inside the onInitDialog Pin
Albert Holguin23-Jan-12 9:20
professionalAlbert Holguin23-Jan-12 9:20 
GeneralRe: Custom drawn button inside the onInitDialog Pin
sdancer7523-Jan-12 20:55
sdancer7523-Jan-12 20:55 
AnswerRe: Custom drawn button inside the onInitDialog Pin
Albert Holguin24-Jan-12 5:09
professionalAlbert Holguin24-Jan-12 5:09 
GeneralRe: Custom drawn button inside the onInitDialog Pin
sdancer7524-Jan-12 21:34
sdancer7524-Jan-12 21:34 
QuestionCScrollView Pin
Bart23-Jan-12 7:21
Bart23-Jan-12 7:21 
AnswerRe: CScrollView Pin
Albert Holguin23-Jan-12 12:12
professionalAlbert Holguin23-Jan-12 12:12 
QuestionDisable OnFileOpen and OnFileSave in SDI Pin
_Flaviu23-Jan-12 5:15
_Flaviu23-Jan-12 5:15 

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.