From: kaz@ashi.FootPrints.net (Kaz Kylheku)
Subject: Re: comma operator: C compiler bug or bogus usage?
Date: 1999/04/15 [thread overview]
Message-ID: <slrn7hcc84.4k7.kaz@ashi.FootPrints.net> (raw)
In-Reply-To: 7f567v$sp1$1@news.iastate.edu
On 15 Apr 1999 17:05:03 GMT, John Hascall <john@iastate.edu> wrote:
># uname -a
>OSF1 pvtest.cc.iastate.edu V4.0 878 alpha
>
># cat ct.c
>#include <stdio.h>
>
>int foo[(3,4)];
>int bar[3,4];
Both of these declare array objects with one dimension, having four
elements.
>main(){ printf("sizes of foo and bar are %d, %d\n", sizeof(foo), sizeof(bar)); }
>
># cc -g -O0 ct.c -o ct
>cc: Error: ct.c, line 4: Missing "]".
Ah, you are being bitten by the fact that 3, 4 is not a constant expression.
Though this is a strange way to report the required diagnostic. :)
The expressions which specify array dimensions must be constant. Expressions
that have a comma operator in them are not considered constant expressions,
even though both of the constituents may be constant expressions.
>int bar[3,4];
>
> constant-expression comma-operator constant-expression
>
> still a constant-expression or not? If not, why not (and it
It's certainly an expression with a value that can be determined at compile
time, no argument there. However, that is not the same as a constant
expression. The latter is just a term that is arbitrarily defined in the C
standard. You have to apply that definition to determine whether something
is a constnat expression or not.
>John
>PS, FWIW, gcc accepts both of these and produces the 'expected' results
It does not if you tell it to be an ANSI C compiler witn -ansi -pedantic.
I tried it with egcs 2.91.57, which accepts it without the -pedantic
option, but produces the following warning if you turn on -pedantic:
warning: ANSI C forbids variable-size array 'a'.
You have fallen into a common pitfall by assuming that your compiler is a C
compiler by default. Many compilers default to supporting their implementor's
extensions, with ANSI C support being a negative option. For example, the
Microsoft compiler supports transparent unions and // comments by
default. GCC supports // comments, statement blocks that behave like
expressions, array sizes that are computed at run time, nested functions and
other goodies.
next prev parent reply other threads:[~1999-04-15 4:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-15 4:00 comma operator: C compiler bug or bogus usage? John Hascall
1999-04-15 4:00 ` Noone Really
1999-04-15 4:00 ` Joerg Czeranski
1999-04-15 4:00 ` Will Rose
1999-04-15 4:00 ` Lawrence Kirby
1999-04-15 4:00 ` Venkat
1999-04-15 4:00 ` Casper H.S. Dik - Network Security Engineer
1999-04-15 4:00 ` Kaz Kylheku [this message]
1999-04-15 4:00 ` John Hascall
1999-04-15 4:00 ` Kaz Kylheku
1999-04-16 4:00 ` Lawrence Kirby
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox