Re: extern

DJ Delorie <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.user
Message-ID <[email protected]>
Typically, you have "extern ..." in all but one source file, and just
"..." in one source file where that symbol is defined.

Saying "extern int foo;" means "I expect some other module to have foo."

Saying "int foo;" means "I have foo."

So exactly one module needs to have foo, to avoid linker errors.

There's an exception in C...

If you have an uninitialized variable, it tells the linker to allocate
space for it (it's a "common symbol" instead of a regular symbol).
IMHO this is bad practice, because it lets two modules think they
"own" a variable, perhaps with two different purposes.

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.