[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[DotGNU]c compiler: Problems with constants
From: |
Alan Jenkins |
Subject: |
[DotGNU]c compiler: Problems with constants |
Date: |
Tue, 23 Mar 2004 09:06:42 +0000 |
User-agent: |
KMail/1.5.4 |
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
- [DotGNU]c compiler: Problems with constants,
Alan Jenkins <=