C53. C Declarations


Declarations

Declarations play a central role in C programming. By declaring variables and functions, we furnish vital information that the compiler will need in order to check a program for potential errors and translate it into object code. It explores the sophisticated options that can be used in declarations and reveals that variable declarations and function dec­larations have quite a bit in common. It also provides a firm grounding in the important concepts of storage duration, scope, and linkage.
Declaration Syntax
Declarations furnish information to the compiler about the meaning of identifiers. When we write
int i ;
we're informing the compiler that, in the current scope, the name i represents a variable of type int.
float f(float);

The declaration tells the compiler that f is a function that returns a float value and has one argu­ment, also of type float.
In general, a declaration has the following appearance:
 declaration-specifiers declarators ;
Declaration specifiers describe the properties of the variables or functions being declared. Declarators give their names and may provide additional information about their properties.
Declaration specifiers fall into three categories:
Storage classes. There are four storage classes: auto, static, extern, and register. At most one storage class may appear in a declaration: if present, it should come first.
Type qualifiers. In C89, there are only two type qualifiers: const and vol­atile. C99 has a third type qualifier, restrict. A declaration may con­tain zero or more type qualifiers.
Type specifiers. The keywords void, char, short, int, long, float, double, signed, and unsigned are all type specifiers. (int unsigned long is the same as long unsigned int). Type specifiers also include specifications of structures, unions, and enumerations (for example, struct point { intx, y; }, struct { intx, y; },or struct point). Type names created using typedef are type specifiers as well.

No comments: