Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a compiler bug, or a C language feature?

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???

like image 824
qstemp Avatar asked Jun 20 '12 09:06

qstemp


1 Answers

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.

like image 138
Daniel Fischer Avatar answered Oct 19 '22 22:10

Daniel Fischer