Re: c compiler: Problems with constants

Rhys Weatherley <[email protected]>
Newsgroups gmane.comp.gnu.dotgnu.developer
Organization Southern Storm Software, Pty Ltd
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.