Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!mcf!mibte!gamma!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: extern - when to use it Message-ID: <9702@alice.UUCP> Date: 29 Jul 89 15:14:20 GMT References: <6420@columbia.edu> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 34 In article <6420@columbia.edu>, kearns@read.columbia.edu (Steve Kearns) writes: > Would someone post an article explaining the proper use of > extern when declaring function? When is it neccessary, > just a good idea, a bad idea? What about the new > 'extern "C" ' I have been hearing about? Saying `extern' by itself in a function declaration has no effect. Thus extern void munge(); means precisely the same thing as void munge(); extern "C" is new in C++ 2.0 . You must use it to declare any C function you wish to call from C++ or any C++ function you wish to call from C: extern "C" double sqrt(double); The declaration informs the C++ compiler that sqrt(double) is a C function so that it can use a C calling sequence for it (which is therefore no longer required to the be the same as the C++ calling sequence). Similarly: extern "C" void frob() { // stuff } says that frob() is a function that will be called from C. -- --Andrew Koenig ark@europa.att.com