RE: gcc v msvc anomaly

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

 



That syntax may be valid for C99 compliant code, but is not valid for
earlier versions of C.  I believe GCC supports the C99 standard.  The
Microsoft compiler likely doesn't, especially if you're using Visual
Studio 6, which I believe was released around 1998 or so (according to
the about box anyway).  So, neither compiler is necessarily wrong - they
just support different versions of the C standard.

Thanks,
Lyle


-----Original Message-----
From: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx] On
Behalf Of Sisyphus
Sent: Thursday, January 27, 2005 2:59 PM
To: gcc
Subject: gcc v msvc anomaly

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