[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [DotGNU]c compiler: Problems with constants
From: |
Rhys Weatherley |
Subject: |
Re: [DotGNU]c compiler: Problems with constants |
Date: |
Tue, 23 Mar 2004 19:38:10 +1000 |
User-agent: |
KMail/1.4.3 |
On Tuesday 23 March 2004 07:06 pm, Alan Jenkins wrote:
> gcc will compile the folowing code, but cscc produces errors for the last
> two statements:
>
> test.c:8: constant value required
> test.c:9: constant value required
Please log this "sizeof" problem in Savannah, so that I don't forget about it.
> I also discovered that the following compiles on gcc but not cscc (syntax
> error, unexpected 'int'). I don't know how important this is:
>
> main ()
> {
> int i;
> {
> /* do nothing*/
> }
> int j;
> }
>
> I guess this is because cscc assumes that something apart from variable
> declarations happens inside the subblock - which excludes futher variable
> declarations i.e. the declaration of j - at the parsing level. Presumably
> gcc leaves this check until later when it can see that the subblock
> contains nothing that is not a variable declaration inside.
Traditional ANSI C only allows declarations at the head of a block. C++
allows them anywhere in a block. The latest version of gcc follows the C++
model. Until recently, such code was considered invalid in C.
I personally think that it *should* be invalid because it causes sloppy coders
to write C code that won't compile on most of the world's existing C
compilers, harming code portability in the process. This is why I do most of
my development with gcc 2.x, not gcc 3.x - the resulting C code is more
portable.
I'll think about it.
Cheers,
Rhys.