INF: goto Label at End of Block Without ";" Invalid Syntax

ID Number: Q64807

4.00 5.00 5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

In Microsoft C versions 5.0, 5.1, 6.0, 6.0a, and 6.0ax, if a goto

label appears last in a block of code, the following compiler error

will be generated:

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

The sample code below illustrates the problem.

More Information:

The semicolon is required by the ANSI definition of the C programming

language. In fact, this situation is described in Section 3.6.3 of the

ANSI standard.

To eliminate the error, use proper syntax as described below.

Sample Code

-----------

#include <stdio.h>

#include <conio.h>

void main(void)

{

char ch;

while(!kbhit())

{

printf("Want to end this loop? (y/n) \n");

if((ch = getche()) == 'y')

{

printf("out of loop\n");

goto mybug;

}

printf("More loop processing here....\n");

mybug: /* This line generates the syntax error */

} /* replace with: mybug: ; */

}

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax