Embedded Systems Design - March 2008 - (Page 12) 0308esd.p09to14 2/13/08 7:42 PM Page 12 programming pointers can place this function declaration in a header, include that header in several source files, compile each file, and link the compiled modules together. Subsequently, all calls to that foo from any of those source files will call the same function. A function declared at file or namespace scope with the keyword static has internal linkage. That is, when you declare: static int foo(int n); Written either way, these declarations are valid in both C and C++, and foo has internal linkage. However, just because you can do this doesn’t mean you should. Writing function declarations that differ only in their storage class specifiers is rarely, if ever, necessary, and can be confusing. If a single identifier has both internal and external linkage in the same translation unit, the resulting program has undefined behavior. That is, it’s an error, but you might not get an error message from the compiler all calls to foo in that translation unit will be to a Written either way, these declarations are function foo defined in that same translation unit. If valid in both C and C++ . . . however, just the translation unit contains calls to foo, yet function foo isn’t defined in that translation unit, the because you can do this doesn’t mean program won’t compile or link, even if there’s a defiyou should. nition for function foo in another translation unit. Table 1 illustrates how C and C++ determine the linkage for a function from the storage class specifier or linker. For example, reversing the order of the extern and static declarations from the previous examand the scope of the function’s declaration. For example, ple, as in: the row labeled extern shows that a function declared extern doesn’t always have external linkage. The row laextern int foo(int n); // external linkage beled none shows that a function declared without a stor age class specifier at file, namespace, or block scope behaves as if it were declared with the keyword extern. static int foo(int n); // undefined behavior For example, a single translation unit can contain the following declarations: yields undefined behavior. All the more reason not to static int foo(int n); // internal linkage write things like this. extern int foo(int n); // still internal The extern declaration could be in an inner scope, as in: static int foo(int n); // internal linkage LINKAGE FOR OBJECTS Table 2 illustrates how C and C++ determine linkage and storage duration for an object from the storage class specifier and the scope of the object’s declaration. It shows, for example, that a non-const object declared at file or namespace scope without a storage class specifier, such as: int n; int bar(int m) { extern int foo(int n); // still internal } has external linkage and static storage duration. This declaration is also a definition in C++ but only a tentative definition in C. Linkage for functions in C and C++. storage class at file scope (C) or specifier namespace scope (C++) auto extern register static at block scope invalid normally external linkage, but possibly internal linkage* invalid invalid same as extern at class scope (only in C++ ) invalid invalid invalid internal linkage external linkage none Table 1 invalid normally external linkage, but possibly internal linkage* invalid internal linkage same as extern *The name has internal linkage if previously declared with internal linkage in a visible declaration. 12 MARCH 2008 | embedded systems design | www.embedded.com http://www.embedded.com
Table of Contents Feed for the Digital Edition of Embedded Systems Design - March 2008 Embedded Systems Design - March 2008 Contents #Include Programming Pointers Designing DSP-based Motor Control Using Fuzzy Logic Hardware/Software Verification Enters the Atomic Age Efficient CRC Calculation with Minimal Memory Footprint Programming Your Own Microcontroller Advertising Index Break Points Marketplace Embedded Systems Design - March 2008 Embedded Systems Design - March 2008 - (Page BB1) Embedded Systems Design - March 2008 - (Page BB2) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page Cover1) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page Cover2) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page 1) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page 2) Embedded Systems Design - March 2008 - Contents (Page 3) Embedded Systems Design - March 2008 - #Include (Page 4) Embedded Systems Design - March 2008 - #Include (Page 5) Embedded Systems Design - March 2008 - #Include (Page 6) Embedded Systems Design - March 2008 - #Include (Page 7) Embedded Systems Design - March 2008 - #Include (Page 8) Embedded Systems Design - March 2008 - Programming Pointers (Page 9) Embedded Systems Design - March 2008 - Programming Pointers (Page 10) Embedded Systems Design - March 2008 - Programming Pointers (Page 11) Embedded Systems Design - March 2008 - Programming Pointers (Page 12) Embedded Systems Design - March 2008 - Programming Pointers (Page 13) Embedded Systems Design - March 2008 - Programming Pointers (Page 14) Embedded Systems Design - March 2008 - Programming Pointers (Page 15) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 16) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 17) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 18) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 19) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 20) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 21) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 22) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 23) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 24) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 25) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 26) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 27) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 28) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 29) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 30) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 31) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 32) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 33) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 34) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 35) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 36) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 37) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 38) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 39) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 40) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 41) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 42) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 43) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 44) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 45) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 46) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 47) Embedded Systems Design - March 2008 - Advertising Index (Page 48) Embedded Systems Design - March 2008 - Break Points (Page 49) Embedded Systems Design - March 2008 - Break Points (Page 50) Embedded Systems Design - March 2008 - Marketplace (Page 51) Embedded Systems Design - March 2008 - Marketplace (Page 52) Embedded Systems Design - March 2008 - Marketplace (Page Cover3) Embedded Systems Design - March 2008 - Marketplace (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.