gcc v msvc anomaly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

--- alloc.c ---
#include <stdio.h>

int main() {
    int i, c = 5, j[c];

    for(i = 0; i < c; ++i) {
        j[i] = i;
        printf("%d ", j[i]);
        }

    printf("\n");

    return 0;
}
--------------

Should that simple script compile and run as expected ?
With my MinGW port of gcc it does - but with Microsoft compilers it won't even compile. I get:


alloc.c(4) : error C2057: expected constant expression
alloc.c(4) : error C2466: cannot allocate an array of constant size 0
alloc.c(4) : error C2133: 'j' : unknown size

Is the Microsoft compiler right in rejecting the code ? If so, has the issue been addressed in later versions of gcc ?

Cheers,
Rob



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux