Click here to Skip to main content
15,915,094 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Bitmap Stuff Pin
Ernest Laurentin11-Dec-01 10:57
Ernest Laurentin11-Dec-01 10:57 
GeneralRe: Bitmap Stuff Pin
Mark Donkers11-Dec-01 11:29
Mark Donkers11-Dec-01 11:29 
GeneralReally Basic Data Type Questions Pin
Stu Pedful11-Dec-01 8:23
Stu Pedful11-Dec-01 8:23 
GeneralRe: Really Basic Data Type Questions Pin
Chris Losinger11-Dec-01 8:41
professionalChris Losinger11-Dec-01 8:41 
GeneralRe: Really Basic Data Type Questions Pin
Stu Pedful11-Dec-01 9:36
Stu Pedful11-Dec-01 9:36 
GeneralRe: Really Basic Data Type Questions Pin
moliate11-Dec-01 21:13
moliate11-Dec-01 21:13 
GeneralThanks! Pin
Stu Pedful12-Dec-01 2:26
Stu Pedful12-Dec-01 2:26 
GeneralRe: Really Basic Data Type Questions Pin
Alvaro Mendez12-Dec-01 8:48
Alvaro Mendez12-Dec-01 8:48 
Stu Pedful wrote:
Isn't this normally true anyway (at least the first part) unless "extern" is used?

No.

Say you declare a variable or function at file scope inside A.cpp:

int nTest = 0;
 
void foo()
{
}


Then you go to file B.cpp and do the same thing:

int nTest = 0;
 
void foo()
{
}


When you go link these two files to create the final executable, the linker will complain that you've multiply defined the same variable and function. Thus, the variable and function in A.cpp are treated as "global" by the linker. When it then sees them also defined in B.cpp, it errors out.

This is different than going to B.cpp and declaring the variable and function extern.

extern int nTest;
 
extern void foo();


In that case, the linker uses the ones defined globally in A.cpp.

To finish my point, by making the variable and function "static", the linker ties them to the files themselves and does not treat them as globals.

static int nTest = 0;
 
static void foo()
{
}


This allows them to be redefined in multiple files without duplicity.

Regards,
Alvaro
GeneralExtern Question Pin
Stu Pedful14-Dec-01 15:19
Stu Pedful14-Dec-01 15:19 
GeneralRe: Extern Question Pin
Alvaro Mendez16-Dec-01 11:36
Alvaro Mendez16-Dec-01 11:36 
GeneralMMC applications Pin
rk200011-Dec-01 8:04
rk200011-Dec-01 8:04 
GeneralRe: MMC applications Pin
Michael Dunn11-Dec-01 8:20
sitebuilderMichael Dunn11-Dec-01 8:20 
GeneralHelp :D Pin
RobJones11-Dec-01 6:55
RobJones11-Dec-01 6:55 
GeneralRe: Help :D Pin
Carlos Antollini11-Dec-01 7:11
Carlos Antollini11-Dec-01 7:11 
QuestionHow to delete a character in CRichEditView? Pin
davilism11-Dec-01 6:42
davilism11-Dec-01 6:42 
AnswerRe: How to delete a character in CRichEditView? Pin
Carlos Antollini11-Dec-01 7:17
Carlos Antollini11-Dec-01 7:17 
GeneralRe: How to delete a character in CRichEditView? Pin
davilism12-Dec-01 6:21
davilism12-Dec-01 6:21 
GeneralChanging dialog size Pin
Chris Losinger11-Dec-01 6:32
professionalChris Losinger11-Dec-01 6:32 
GeneralRe: Changing dialog size Pin
Carlos Antollini11-Dec-01 6:49
Carlos Antollini11-Dec-01 6:49 
GeneralRe: Changing dialog size Pin
Chris Losinger11-Dec-01 7:43
professionalChris Losinger11-Dec-01 7:43 
GeneralRe: Changing dialog size Pin
Carlos Antollini11-Dec-01 8:29
Carlos Antollini11-Dec-01 8:29 
GeneralRe: Changing dialog size Pin
Chris Losinger11-Dec-01 8:32
professionalChris Losinger11-Dec-01 8:32 
QuestionChanging the size of the window? Pin
Chambers11-Dec-01 5:56
Chambers11-Dec-01 5:56 
AnswerRe: Changing the size of the window? Pin
NormDroid11-Dec-01 6:05
professionalNormDroid11-Dec-01 6:05 
GeneralRe: Changing the size of the window? Pin
Chambers12-Dec-01 1:31
Chambers12-Dec-01 1:31 

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.