c/language/declarations

A declaration is a C language construct that introduces one or more s into the program and specifies their meaning and properties.

Declarations may appear in any scope. Each declaration ends with a semicolon (just like ) and consists of distinct parts:

where

@1-2@ Simple declaration. Introduces one or more identifiers which denotes objects, functions, struct/union/enum tags, typedefs, or enumeration constants. @3@ Attribute declaration. Does not declares any identifier, and has implementation-defined meaning if the meaning is not specified by the standard.

For example,

The type of each identifier introduced in a declaration is determined by a combination of the type specified by the and the type modifications applied by its.

may appear in, in which case they apply to the type determined by the preceding specifiers.

Declarators
Each declarator is one of the following:

@1@ the identifier that this declarator introduces. @2@ any declarator may be enclosed in parentheses; this is required to introduce pointers to arrays and pointers to functions. @3@ : the declaration ; declares as a -qualified pointer to the type determined by. @4@ : the declaration declares  as an array of  objects of the type determined by. is any other declarator except unparenthesized pointer declarator. @5@ : the declaration declared  as a function taking the parameters  and returning. is any other declarator except unparenthesized pointer declarator.

The reasoning behind this syntax is that when the identifier declared by the declarator appears in an expression of the same form as the declarator, it would have the type specified by the type specifier sequence.

The end of every declarator that is not part of another declarator is a.

In all cases, is an optional sequence of. When appearing immediately after the identifier, it applies to the object or function being declared.

Definitions
A definition is a declaration that provides all information about the identifiers it declares.

Every declaration of an or a  is a definition.

For functions, a declaration that includes the function body is a :

For objects, a declaration that allocates storage (, but not extern) is a definition, while a declaration that does not allocate storage is not.

For s and s, declarations that specify the list of members are definitions:

Redeclaration
A declaration cannot introduce an identifier if another declaration for the same identifier in the same appears earlier, except that
 * Declarations of objects (external or internal) can be repeated:


 * Non-VLA can be repeated as long as it names the same type:


 * and declarations can be repeated:

These rules simplify the use of header files.