5

My environment is Windows XP SP3 + 'Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86'. The process is as follows:

F:\workshop\vc8proj\console> type t.c

int main(void) {

    // Do some thing.
    {
        int i;
        {
            i = 3;
            goto abc111;
        }

        abc111:
    }
    return 0;
}

F:\workshop\vc8proj\console> cl /MD t.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

Copyright (C) Microsoft Corporation. All rights reserved.

t.c t.c(10) : error C2143: syntax error : missing ';' before '}'

F:\workshop\vc8proj\console>vim t.c

F:\workshop\vc8proj\console>type t.c

int main(void) {
    // Do some thing.
    {
        int i;
        {
            i = 3;
            goto abc111;
        }

        abc111: 5201314;
    }
    return 0;
}

F:\workshop\vc8proj\console> cl /MD t.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

Copyright (C) Microsoft Corporation. All rights reserved.

t.c Microsoft (R) Incremental Linker Version 8.00.50727.762 Copyright (C) Microsoft Corporation. All rights reserved.

/out:t.exe t.obj

F:\workshop\vc8proj\console>

Under the Linux operating system the same situation, too???

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
qstemp
  • 51
  • 2

2 Answers2

11

It's a language feature. A label can only be part of a labeled statement, and the statement needs a terminating ;. Just putting a semicolon behind the label suffices.

int main(void) {

    // Do some thing.
    {
        int i;
        {
            i = 3;
            goto abc111;
        }

        abc111: ;

    }
    return 0;
}

works too.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
1

Well, it is a language feature. It is compulsory that there should be a statement to which we mentioned the label.

If there isn't any statement after the label then just put a ';' to terminate the statement or you can write a return statement after the label only.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131