c compiler: Problems with constants

Alan Jenkins <[email protected]>
Newsgroups gmane.comp.gnu.dotgnu.developer
Message-ID <[email protected]>
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

main () {
	/* sizeof void * and long appear to be compile-time constants */
	{
		char c [sizeof (long)];
		char d [sizeof (void *)];
	}
	/* but not if you add one... */
	{
		char c [sizeof (long) + 1];
		char d [sizeof (void *) + 1];
	}
	/* but addition of literal constants doesn't cause problems... */
	{
		char c [8 + 1];
		char d [4 + 1];
	}
}

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.

Thanks in advance

Alan Jenkins
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.