Embedded Systems Design - March 2008 - (Page 9) 0308esd.p09to14 2/13/08 7:42 PM Page 9 BY Dan Saks programming pointers Linkage in C and C++ name declared in C or C++ In my earlier article on the scope may have attributes such as rules,1 I explained the distinction between declarations and definitype, scope, storage durations, but omitted some details. tion, and linkage. Not every name Those details are pertinent to the has all of these attributes. For examconcept of linkage, so let’s take a ple, a function name has a type, a look at them first. scope, and a linkage, but no storage duration. A statement label name DECLARATIONS AND has only a scope. DEFINITIONS An object’s type determines the A declaration associates attributes object’s size and memory address with names. A declaration either inalignment, the values the object can troduces a name into the current have, and the operations that can be translation unit or redeclares a name performed on that object. A funcintroduced by a declaration that aption’s type specifies the function’s peared earlier in the same translaparameter list and return type. tion unit. A declaration for a name A name’s scope is that portion of might also be a definition. Informala translation unit in which the ly, a definition is a declaration that name is visible.1 (A translation unit is the source code produced by the not only says “here’s a name,” but Scope determines what preprocessor from a source file and also “here’s all the information the you can see within a trans- compiler needs to create the code all its included headers.) C supports four different kinds of scope: for that name”. lation unit. Linkage deterfile scope, block scope, function C++ lets you declare all sorts of mines what you can see prototype scope, and function things that aren’t valid in C, such as across translation units. scope. C++ generalizes file scope classes, namespaces, and linkage into namespace scope, and adds specifications. Not surprisingly, these class scope. features make the distinction between definitions and other An object’s storage duration determines the lifetime of declarations, as well as the linkage rules, more complicated the storage for that object.2 That is, it determines how and in C++ than in C. However, we don’t really need to considwhen during program execution the storage for that ober all those features to explain linkage—using just functions ject comes and goes. Each object in C and C++ has one of and objects should provide adequate illustration. the following three storage durations: static, automatic, For function declarations that are valid in both C and and dynamic. Only objects have storage duration. EnuC++, the rule for deciding when a function declaration is meration constants, functions, labels, and types don’t. also a definition is the same for both languages, namely, Which brings us to linkage. A name’s linkage affects that a function declaration is also a function definition if whether two or more declarations for that name are valid, it includes a brace-enclosed body, as in: and if so, whether they refer to the same entity (such as a int abs(int v) function or an object). Understanding linkage clears up a { number of misconceptions about the behavior of C and return v < 0 ? -v : v; C++ programs. }; A Dan Saks is president of Saks & Associates, a C/C++ training and consulting company. For more information about Dan Saks, visit his website at www.dansaks.com. Dan also welcomes your feedback: e-mail him at dsaks@wittenberg.edu. A function heading without a body, as in: int abs(int v); is just a declaration. www.embedded.com | embedded systems design | MARCH 2008 9 http://www.dansaks.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.