Chapter 11. Declarations

A declaration determines the significance and properties of one or more identifiers . The identifiers you declare can be the names of objects, functions, types, or other things, such as enumeration constants. Identifiers of objects and functions can have various types and scopes. The compiler needs to know all of these characteristics of an identifier before you can use it in an expression. For this reason, each translation unit must contain a declaration of each identifier used in it.

Labels used as the destination of goto statements may be placed before any statement. These identifiers are declared implicitly where they occur. All other identifiers require explicit declaration before their first use, either outside of all functions or at the beginning of a block. In C99, declarations may also appear after statements within a block.

After you have declared an identifier, you can use it in expressions until the end of its scope. The identifiers of objects and functions can have file or block scope (see "Identifier Scope" in Chapter 1).

General Syntax

There are several different kinds of declarations:

  • Declarations that only declare a structure, union, or enumeration tag, or the members of an enumeration (that is, the enumeration constants)

  • Declarations that declare one or more object or function identifiers

  • typedef declarations, which declare new names for existing types

Declarations of enumerated, structure, and union types are described in Chapter 2 and Chapter ...

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.