6.8.3 Expression and null statements

Syntax

1

expression-statement:

expressionopt ;

Semantics

2

The expression in an expression statement is evaluated as a void expression for its side effects.[1]

3

A null statement (consisting of just a semicolon) performs no operations.

4

EXAMPLE 1 If a function call is evaluated as an expression statement for its side effects only, the discarding of its value may be made explicit by converting the expression to a void expression by means of a cast:

int p(int);
/* ... */
(void)p(0);

5

EXAMPLE 2 In the program fragment

char *s;
/* ... */
while (*s++ != '\0')
        ;

a null statement is used to supply an empty loop body to the iteration statement.

6

EXAMPLE 3 A null statement may also be used to carry a label just before the closing } of a compound statement.

while (loop1) {
      /* ... */
      while (loop2) {
              /* ... */
              if (want_out)
                      goto end_loop1;
              /* ... */
      }
      /* ... */
end_loop1: ;
}

Forward References

Footnotes