INF: Using Goto Label Before Closing Brace Causes C2143 Error

ID Number: Q70059

5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

In Microsoft C versions 5.1, 6.0, 6.0a, 6.0ax, and C/C++ 7.0, when

using a goto statement, the label referenced by that statement must be

followed by a null statement (a semicolon) if it immediately precedes

a closing curly brace (}). Failure to include a semicolon (;) in this

case results in the following compiler error:

error C2143: syntax error : missing ';' before '}'

More Information:

The requirement of the null statement before the closing curly brace

is part of the C language and is documented in the ANSI specification

in Section 3.6.3 as follows:

A null statement may also be used to carry a label just before

the closing } of a compound statement.

To eliminate a C2143 error caused by this situation, add a semicolon

after the label. For example, the sample code below generates this

error, which can be eliminated if the line with the label is changed

to the following:

Label:;

Sample Code

-----------

/* Compile options needed: none

*/

void main(void)

{

goto Label;

Label: /* A semicolon should follow this label */

}

Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00 s_quickc