Weird identifier declaration
Nigel Holder
nigel at wraxall.inmos.co.uk
Wed Aug 23 22:54:45 AEST 1989
Reading the ANSI spec closely I found the following weird case that
enables the declaration of identifiers *after* assignment statements
within the same block by using 'sizeof (type-name)'.
The best way to illustrate this is with an example :-
int main (void)
{
int a;
a = 3;
(void) sizeof (enum colour {red, green, blue});
printf ("red = %d, green = %d, blue = %d\n", red, green, blue);
}
The behaviour is similar to :-
int main (void)
{
...
{
enum colour {red, green, blue};
printf ( ...
}
}
I guess the question is was this intentional ?
(just for record you can also use the following instead of sizeof () :
a = (enum colour {red, green, blue})3;
as well !).
Nigel Holder, INMOS Limited | mail[uk]: nigel at inmos.co.uk or ukc!inmos!nigel
1000 Aztec West, Bristol, UK | [us]: uunet!inmos-c!nigel
Phone: +44 454 616616 x508 | Internet: @col.hp.com:nigel at inmos-c
More information about the Comp.std.c
mailing list