From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,4873305131bf4d94 X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,4873305131bf4d94 X-Google-Attributes: gid1014db,public From: seebs@plethora.net (Peter Seebach) Subject: Re: Mixing declarations and statements (Re: Porting (was ADA and Pascal etc)) Date: 1997/11/04 Message-ID: <63nlk6$h0e$1@darla.visi.com>#1/1 X-Deja-AN: 287916243 References: <34557f2b.1934172@news.mindspring.com> <63d5l4$tub$1@helios.crest.nt.com> <878495810snz@genesis.demon.co.uk> Organization: Plethora Internet NNTP-Posting-Date: 04 Nov 1997 11:22:14 CST Newsgroups: comp.lang.ada,comp.lang.c Date: 1997-11-04T11:22:14-06:00 List-Id: In article , �amonn McManus wrote: >with the exciting new feature you can write: > switch (thing) { > case one: > int x = whatever(); > use(x); > break; > case two: > int x = maybe(); > use(x); > break; > } >Except I very much hope that you can't, since that would be a multiple >declaration of x. I think you are correct. >Presumably the new C will allow the first >declaration but require the `int' to be left off the second, turning >it back into a lowly statement. Yes. >That's terrible programming practice of >course because you're having the meaning of one switch case depend on >the way another one was written. So, what you might do is switch (thing) { int x; case one: ... } and, of course, you can't count on x being initialized, because you'll be jumping in past the initializer. >Nonetheless the new C feature is easy to implement and understand and is >fairly often useful. That's my reading of it. I still slightly prefer blocks, so I can clearly end the scope of a declaration, but that's just a matter of personal style. -s -- seebs@plethora.net -- Speaking for myself. No spam please. Copyright 1997. All rights reserved. This was not written by my cat. C/Unix wizard - send mail for help! -- - More Net, Less Spam!