C__DOCUME~1_MAXWID~1_LOCALS~1_Temp_plugtmp-27_lecture20_AdvDeclarations

C__DOCUME~1_MAXWID~1_LOCALS~1_Temp_plugtmp-27_lecture20_AdvDeclarations

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 ee312 Spring 2008 Lecture 20 Lecture 20 Read ch. 20 for Next Lecture Low Level Programming Topics for Today Advanced Declarations Good Programming Techniques 1 ee312 Spring 2008 Lecture 20 Declaration Syntax A declaration tells the C compiler about the properties of variables and/or functions. Declarations have the form declaration-specifiers declarators ; Each declarator may be followed by an initializer. Examples of declarations: static float x, y, *p; const char computer = "Dell laptop"; extern unsigned long int a[10], j; extern double f(double a); A declaration specifier is one of the following: Storage class (auto, static, extern, or register) Type specifier (for example, long, short, unsigned, int, or float) Type qualifier (const or volatile) At most one storage class is allowed; if present, it should come first. There may be several type specifiers and/or qualifiers; in any order. 2 2 ee312 Spring 2008 Lecture 20 Storage Class of a Variable The choice of storage class affects a variables storage duration, scope, and linkage. The storage duration of a variable is the portion of program execution during which storage for the variable exists. Choices: Automatic Storage for the variable is allocated when the surrounding block is executed; storage is deallocated when the block terminates, causing the variable to lose its value. Static The variable has a permanent storage location, hence it retains its value throughout the execution of the program. The scope of a variable is the portion of the program text in which the variable can be referenced. Choices: Block scope The variable is visible from its point of declaration to the end of the enclosing block. File scope The variable is visible from its point of declaration to the end of the enclosing file. 3 ee312 Spring 2008 Lecture 20 Storage Classes (2) The linkage of a variable determines whether it may be shared by more than one file in the same program. Choices: External The same variable may be shared by several files. Internal The variable is restricted to a single file. None The variable belongs to a single function and cant be shared at all. A variables default storage duration, scope, and linkage depend on where the variable is declared: Inside a block: The variables storage duration is automatic and it has block scope. At the outermost level of a program: The variables storage duration is static, it has file scope, and its linkage is external. 3 4 ee312 Spring 2008 Lecture 20 Storage Classes (3) The programmer can specify the storage class of a variable: either auto, static, extern, or register....
View Full Document

This note was uploaded on 04/15/2008 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 29

C__DOCUME~1_MAXWID~1_LOCALS~1_Temp_plugtmp-27_lecture20_AdvDeclarations

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online