Re: [psas-avionics] code question...
In message 49df660f.1060...@ytivarg.com you wrote: Barton C Massey wrote: It's a less-than-good feature of C. Case labels are labels, and thus must label a statement. For what it's worth, in object-oriented land (I mainly do Java these days) case statements are also (supposed to be) atomic operations. Same idea, slightly different syntax. I'm not sure what you mean here. In Java declarations are statements, as they should be[*], and so you can put them right after a case label and everything works great. (Duff's Device is also illegal in Java, which is a bit sad. Case labels must occur only immediately inside a switch.) Bart [*] Actually, declarations should be expressions, as they are in Nickle (http://nickle.org). This allows some convenient and clear notation, such as scanf(%d %d, (int x), (int y)); printf(%d %d\n, x, y); ___ psas-avionics mailing list psas-avionics@lists.psas.pdx.edu http://lists.psas.pdx.edu/mailman/listinfo/psas-avionics
Re: [psas-avionics] code question...
In message 8f5d905c0904091948y526182edm16cb2bf4d5a42...@mail.gmail.com you wrote: It turns out wrapping that last case in curly-braces makes everything happy and compileable... Not that this is comfortable... It's a less-than-good feature of C. Case labels are labels, and thus must label a statement. My version of gcc gives the helpful error message error: a label can only be part of a statement and a declaration is not a statement, which pretty much summarizes the problem. Ironically, sticking a semicolon right after the colon in the case label makes it label an empty statement, making the whole thing OK again. Please don't do that. :-) In any case, as gcc says with -ansi -pedantic, warning: ISO C90 forbids mixed declarations and code. C99 does not, which is how it should have been from day 1 in the C language. Bart ___ psas-avionics mailing list psas-avionics@lists.psas.pdx.edu http://lists.psas.pdx.edu/mailman/listinfo/psas-avionics