Click here to Skip to main content
15,910,787 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGlobal Variables in SDI Pin
hellogany18-Apr-10 22:33
hellogany18-Apr-10 22:33 
AnswerRe: Global Variables in SDI Pin
LittleYellowBird18-Apr-10 22:55
LittleYellowBird18-Apr-10 22:55 
GeneralRe: Global Variables in SDI Pin
hellogany18-Apr-10 22:57
hellogany18-Apr-10 22:57 
GeneralRe: Global Variables in SDI Pin
KarstenK18-Apr-10 23:32
mveKarstenK18-Apr-10 23:32 
GeneralRe: Global Variables in SDI Pin
hellogany18-Apr-10 23:39
hellogany18-Apr-10 23:39 
GeneralRe: Global Variables in SDI Pin
KarstenK18-Apr-10 23:45
mveKarstenK18-Apr-10 23:45 
QuestionRe: Global Variables in SDI Pin
David Crow19-Apr-10 3:19
David Crow19-Apr-10 3:19 
GeneralRe: Global Variables in SDI Pin
LittleYellowBird18-Apr-10 23:50
LittleYellowBird18-Apr-10 23:50 
GeneralRe: Global Variables in SDI Pin
hellogany19-Apr-10 0:02
hellogany19-Apr-10 0:02 
GeneralRe: Global Variables in SDI Pin
hellogany19-Apr-10 0:06
hellogany19-Apr-10 0:06 
GeneralRe: Global Variables in SDI Pin
David Crow19-Apr-10 3:22
David Crow19-Apr-10 3:22 
GeneralRe: Global Variables in SDI Pin
LittleYellowBird19-Apr-10 0:12
LittleYellowBird19-Apr-10 0:12 
GeneralRe: Global Variables in SDI Pin
CPallini19-Apr-10 0:18
mveCPallini19-Apr-10 0:18 
GeneralRe: Global Variables in SDI Pin
hellogany19-Apr-10 0:26
hellogany19-Apr-10 0:26 
GeneralRe: Global Variables in SDI Pin
Cedric Moonen19-Apr-10 0:52
Cedric Moonen19-Apr-10 0:52 
GeneralRe: Global Variables in SDI Pin
LittleYellowBird19-Apr-10 0:26
LittleYellowBird19-Apr-10 0:26 
GeneralRe: Global Variables in SDI Pin
CPallini19-Apr-10 0:37
mveCPallini19-Apr-10 0:37 
GeneralRe: Global Variables in SDI Pin
LittleYellowBird19-Apr-10 0:45
LittleYellowBird19-Apr-10 0:45 
GeneralRe: Global Variables in SDI Pin
CPallini19-Apr-10 0:50
mveCPallini19-Apr-10 0:50 
GeneralRe: Global Variables in SDI Pin
hellogany19-Apr-10 0:58
hellogany19-Apr-10 0:58 
GeneralRe: Global Variables in SDI Pin
CPallini19-Apr-10 1:20
mveCPallini19-Apr-10 1:20 
GeneralRe: Global Variables in SDI Pin
hellogany19-Apr-10 17:00
hellogany19-Apr-10 17:00 
GeneralRe: Global Variables in SDI Pin
CPallini19-Apr-10 22:02
mveCPallini19-Apr-10 22:02 
GeneralRe: Global Variables in SDI Pin
Iain Clarke, Warrior Programmer19-Apr-10 23:13
Iain Clarke, Warrior Programmer19-Apr-10 23:13 
The problem here is that you have a terminology issue.

You declare the variable in HEADER file (something.h) that can be freely included in SOURCE files (*.c / *.cpp)
extern int g_MyVariable


Where you and other have an issue is that you implement the variable in another .h file, that you actually treat like a source file.
So, your compiler builds some cpp file, that is the only file including this special header.

As long as you are disciplined about this, you'll be fine.

But anyone else coming along will be puzzled.

Some day you'll make a mistake...

If you put the actual implementation
int g_MyVariable = 0;

in a source file, then you can't make this mistake.

OK, you can, but any line like:
#include "globalvars.cpp"

is going to be really obvious.

I hope that helps a little...

Iain.
I have now moved to Sweden for love (awwww).

GeneralRe: Global Variables in SDI Pin
hellogany20-Apr-10 20:22
hellogany20-Apr-10 20:22 

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.