Path: utzoo!attcan!uunet!ginosko!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!att!cbnewsl!dfp From: dfp@cbnewsl.ATT.COM (david.f.prosser) Newsgroups: comp.std.c Subject: Re: Weird identifier declaration Message-ID: <1611@cbnewsl.ATT.COM> Date: 24 Aug 89 17:53:30 GMT References: <1898@brwa.inmos.co.uk> Reply-To: dfp@cbnewsl.ATT.COM (david.f.prosser) Organization: AT&T Bell Laboratories Lines: 32 In article <1898@brwa.inmos.co.uk> nigel@inmos.co.uk () writes: >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) >{ > (void) sizeof (enum colour {red, green, blue}); > printf ("red = %d, green = %d, blue = %d\n", red, green, blue); >} > >I guess the question is was this intentional ? The charter for X3J11 was "to codify existing practice wherever unambiguous" [FORWARD, page v]. As this has been the behavior of most implementations, the answer was clear. Besides, what other reasonable ruling could be made for this sort of code? Disallow it, without disallowing all "reasonable" uses for casts and sizeof? Allow it, but define another form of scope that extends to the end of the type-name, or the expression statement, or somewhere in between? >(just for record you can also use the following instead of sizeof () : > a = (enum colour {red, green, blue})3; >as well !). True enough. Any expression that includes the possibility of a type specifier allows for extra declarations. This only includes casts and sizeof. Dave Prosser ...not an official X3J11 answer...