public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: gcc v msvc anomaly
@ 2005-01-27 23:33 lrtaylor
  2005-01-28  1:20 ` Sisyphus
  0 siblings, 1 reply; 3+ messages in thread
From: lrtaylor @ 2005-01-27 23:33 UTC (permalink / raw)
  To: kalinabears, gcc-help

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@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gcc v msvc anomaly
  2005-01-27 23:33 gcc v msvc anomaly lrtaylor
@ 2005-01-28  1:20 ` Sisyphus
  0 siblings, 0 replies; 3+ messages in thread
From: Sisyphus @ 2005-01-28  1:20 UTC (permalink / raw)
  To: lrtaylor; +Cc: gcc-help

lrtaylor@micron.com wrote:
> 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.
MSVC++ 7.0 is the same as 6.0 - I don't have anything later than that to 
test with.

So ... with MS compilers, I presume I have to allocate dynamically - ie 
if I'm not prepared to declare with a constant expression. (Could 
someone let me know if there's some other workaround.)

Cheers,
Rob

^ permalink raw reply	[flat|nested] 3+ messages in thread

* gcc v msvc anomaly
@ 2005-01-27 23:05 Sisyphus
  0 siblings, 0 replies; 3+ messages in thread
From: Sisyphus @ 2005-01-27 23:05 UTC (permalink / raw)
  To: gcc

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-01-28  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-27 23:33 gcc v msvc anomaly lrtaylor
2005-01-28  1:20 ` Sisyphus
  -- strict thread matches above, loose matches on Subject: below --
2005-01-27 23:05 Sisyphus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).