Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: [ On topic, amazingtly ]: labels and declarations Date: Sun, 17 Mar 2019 16:16:01 -0700 Organization: None to speak of Lines: 28 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="dffa6b7d2dd8d0122e38bd70d28a7fdc"; logging-data="32173"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uheKLLbKsfJaChce5bQfg" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:mBmj70HCA0K6XWZytlqFcJv/Wt4= sha1:xhSo/e9hZnw7YQF/+fZwMDb+jPY= Xref: csiph.com comp.lang.c:142003 Richard Damon writes: [...] > This unfortunately leads to the following being grammatically correct: > > if(flag) int x; > > which would mean that the following code might be valid or not depending > of if flag was true at run time, or > > if(flag) int x; > else float x; > > where the type of x changes at run time, or even [...] C++ allows this; a declaration (if it appears inside a function defintion) is a kind of statement. The scope of x is limited to the declaration-statement, so the above is equivalent to: if (flag) { int x; } else { float x; } which is valid in C. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */