7.2 Compound Statements

A compound statement, or block, allows a sequence of statements to be treated as a single statement. A compound statement begins with a left brace, contains optional declarations followed optionally by statements, and ends with a right brace, as shown in the following example:

{
   int x = 5;

   z = 1;
   if (y < x)
      funct(y, z);
   else
      funct(x, z);
}

Block declarations are local to the block, and, for the rest of the block, they supersede other declarations of the same name in outer scopes.

A block is entered normally when control flows into it, or when a goto statement transfers control to a label at the beginning of the block itself. Each time the block is entered normally, storage is allocated for auto or register variables. If, on the other hand, a goto statement transfers control to a label inside the block or if the block is the body of a switch statement, these storage allocations do not occur. For more information about storage classes, see Section 2.10.

Function definitions contain compound statements. The compound statement following the parameter declarations in a function definition is called the function body.


Previous Page | Next Page | Table of Contents | Index