Embedded Systems Design - March 2008 - (Page 14) 0308esd.p09to14 2/13/08 7:42 PM Page 14 programming pointers Linkage and storage duration for objects in C and C++. storage class at file scope (C) or specifier namespace scope (C++) auto extern at block scope no linkage; automatic storage normally external linkage, but possibly internal linkage;* static storage same as auto no linkage; static storage same as auto at class scope (only in C++ ) invalid invalid register static none invalid normally external linkage, but possibly internal linkage;* static storage invalid internal linkage; static storage normally external linkage, except that const objects in C++ have internal linkage; static storage invalid external linkage; static storage no linkage; same storage duration as enclosing object *The name has internal linkage if previously declared with internal linkage in a visible declaration. Table 2 With many C compilers, you can place this declaration in a header, include that header in several source files, compile each source file, and link them together. The linker will treat one of those tentative definitions as a definition and all the other tentative definitions as declarations referring to that definition. This behavior is a common extension to the C standard, but may not be portable to all C environments, and doesn’t work in C++. Using C++, you’ll get a link error complaining about a multiply-defined symbol. If you want the code to compile and link in C++ as well as C, you must declare n with the extern specifier, as in: extern int n; both parameter v and local object n have no linkage. You can’t write a declaration for an integer v elsewhere and get it to link to foo’s parameter v. Likewise for n. Thus, the two objects named n in this example are distinct objects. If you add the static storage class specifier to the declaration of n at block scope, you change its storage duration but not its linkage. For example: static int n; int foo(int v) { static int n; } // still internal linkage // still no linkage As before, n has external linkage, but now the declaration is not a definition—not even a tentative one in C. You can place this declaration in a header, include that header in several source files, compile each source file, and link them together. But you’ll still get a link error, unless there’s exactly one definition for all those declarations to reference. Just one of the source files must provide a definition for n. Any one of the following definitions will do: int n; int n = 0; extern int n = 0; defines two distinct objects named n, both with static storage duration. The n at block scope still has no linkage. There’s more to say about linkage, but this is enough for now. ■ ENDNOTES: 1. Saks, Dan, “Scope regions in C and C++,” Embedded Systems Design, November, 2007, p. 15. Available online at www.embedded.com/columns/programmingpointers/ 202600398. Saks, Dan, “Storage class specifiers and storage duration,” Embedded Systems Design, January, 2008, p. 9. Available online at www.embedded.com/columns/programmingpointers/ 205203843. An object declared at block scope without a storage class specifier has automatic storage duration and no linkage. For example, in: static int n; int foo(int v) { int n; } // internal linkage 2. ACKNOWLEDGMENTS: // no linkage My thanks to Steve Adamczyk of the Edison Design Group (www.edg.com), Tom Plum of Plum Hall (www.plumhall.com), and Joel Saks (www.joelsaks.com) for their valuable assistance with this article. 14 MARCH 2008 | embedded systems design | www.embedded.com http://www.embedded.com/columns/programmingpointers/202600398 http://www.embedded.com/columns/programmingpointers/205203843 http://www.embedded.com/columns/programmingpointers/205203843 http://www.plumhall.com http://www.edg.com http://www.joelsaks.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.