Add Book to My BookshelfPurchase This Book Online

Appendix A - Significant Changes in ANSI C

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Declarations
The ANSI C standard has cleaned up variable declarations, both by formalizing the use of some non-standard types, and defining a few new ones.
The void Type
Most newer non-ANSI compilers accept some form of the void type, but support for all of its features is varied. The void type has three uses in ANSI C:
 1.Declaring a function with a return type of void means that the function returns no value. By declaring functions that do have a return value appropriately, and indicating functions that do not have a return value with a type of void, the compiler can perform type checking for the programmer.
 2.Declaring a function prototype (see below) with a parameter specification of void means that the function has no arguments. The compiler can use this for checking parameter lists in function calls.
 3.The type void * is now used as the universal pointer. Prior to the invention of void, the char * type was usually used; this did not work well on systems that used different sized pointers for different objects.
The enum Type
The ANSI C standard has officially codified the enum data type. Use of enum variables as array subscripts is explicitly allowed; some compilers previously disallowed this.
The char Type
Because there is no standard among hardware vendors as to whether a char is signed or unsigned, there is also no standard defined by ANSI. The signedness or unsignedness of a char in ANSI C is explicitly hardware-dependent.
If a specific type (signed or unsigned) is needed, the familiar unsigned qualifier and the new-to-ANSI signed qualifier may be used when declaring variables of type char.
Type Qualifiers
ANSI C has defined two new type qualifiers:
const
This qualifier identifies a constant, indicating that the object will not be modified. This allows the compiler to refuse to modify the object; it also allows the compiler more freedom in making optimizations. Note that initializing an object is not the same as modifying the object. For example, the following is perfectly legal:
    const int True = 1;
The use of the const qualifier is somewhat tricky, however. For example, the declaration
    const char *s;
means that s will only point at characters that will not be modified through s (although they might be modified through some other means). It does not mean that s will not be modified. To declare that, you would instead say
    char *const s;
volatile
This is the opposite of const. It tells the compiler that this variable may change in ways the compiler cannot predict. Basically, it tells the compiler not to optimize references to this variable, since the optimizations may not be accurate in all circumstances.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback