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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,4873305131bf4d94 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,4873305131bf4d94 X-Google-Attributes: gid103376,public From: kaz@helios.crest.nt.com (Kaz Kylheku) Subject: Re: Mixing declarations and statements (Re: Porting (was ADA and Pascal etc)) Date: 1997/11/04 Message-ID: <63p30l$e$1@helios.crest.nt.com>#1/1 X-Deja-AN: 288023990 References: <34557f2b.1934172@news.mindspring.com> <63nlk6$h0e$1@darla.visi.com> <345F6265.A505E2FC@earthling.net> Organization: A poorly-installed InterNetNews site Newsgroups: comp.lang.ada,comp.lang.c Date: 1997-11-04T00:00:00+00:00 List-Id: In article <345F6265.A505E2FC@earthling.net>, Charles Hixson wrote: >Peter Seebach wrote: >/* snip */ >> >> >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. >> >Actually, I believe that it's worse than that. The variables are >allocted at run time, so if the first case doesn't end with a break, >then if you follow the path through the first case, then the second case >MUST NOT declare the int, but only use it. However if you follow the >path directly through the second case, then the second case MUST delcare >the int. And this can only be detected at run-time (I hope I'm wrong >about this. It's been a few of years since I did any significant amout >of C programming, and I stayed away from this kind of construct then, >but that's the way I remember it). That isn't how these languages generally work. Declarations are gathered by the translator, and it can then decide how automatic storage shall be laid out prior to the program's execution. In C, an object has defined storage whether or not you skip its declarator. A declarator is not an executable statement which dynamically allocates storage! However, if you skip over declarations, their associated initializations will not be performed. For example: goto there; /* no problem */ { int x = 2; there: x = 1; There is nothing incorrect about doing this. The object x is defined even if you jump into the middle of the block. But at that point, it has an indeterminate value, rather than the value 2. This is corrected in the subsequent statement which assigns it the value 1. -- "In My Egotistical Opinion, most people's C programs should be indented six feet downward and covered with dirt." -- Blair P. Houghton