Programming in C

(Barry) #1
452 Appendix A C Language Summary


  1. Conversion of a signed integer to a longer integer results in extension of the sign
    to the left; conversion of an unsigned integer to a longer integer results in zero fill
    to the left.

  2. Conversion of any value to a _Boolresults in 0 if the value is zero and 1 other-
    wise.

  3. Conversion of a longer integer to a shorter one results in truncation of the integer
    on the left.

  4. Conversion of a floating-point value to an integer results in truncation of the deci-
    mal portion of the value. If the integer is not large enough to contain the convert-
    ed floating-point value, the result is not defined, as is the result of converting a
    negative floating-point value to an unsigned integer.

  5. Conversion of a longer floating-point value to a shorter one might or might not
    result in rounding before the truncation occurs.


6.0 Storage Classes and Scope
The term storage classrefers to the manner in which memory is allocated by the compil-
er in the case of variables and to the scope of a particular function definition. Storage
classes are auto,static,extern,and register.A storage class can be omitted in a dec-
laration and a default storage class is assigned, as discussed later in this chapter.
The term scoperefers to the extent of the meaning of a particular identifier within a
program. An identifier defined outside any function or statement block (herein referred
to as a BLOCK) can be referenced anywhere subsequent in the file. Identifiers defined
within a BLOCK are local to that BLOCK and can locally redefine an identifier defined
outside it. Label names are known throughout the BLOCK, as are formal parameter
names. Labels, structure and structure member names, union and union member names,
and enumerated type names do not have to be distinct from each other or from variable
or function names. However, enumeration identifiers dohave to be distinct from variable
names and from other enumeration identifiers defined within the same scope.

6.1 Functions


If a storage class is specified when a function is defined, it must be either staticor
extern. Functions that are declared as staticcan only be referenced from within the
same file that contains the function. Functions that are specified as extern(or that have
no class specified) can be called by functions from other files.

6.2 Variables


Ta b le A.6 summarizes the various storage classes that can be used in declaring variables
as well as their scope and methods of initialization.

20 0672326663 AppA 6/10/04 2:01 PM Page 452

Free download pdf