Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: for-loop scopes Date: Thu, 23 Mar 2017 08:37:27 -0700 Organization: None to speak of Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="1b33b319c9f9fcfff45ec1f5b5f6ee2d"; logging-data="20809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ECQtK1k9XAIwrFORQlv4K" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:BP72G3SG4v9sFlNkZKr7/tAI1A4= sha1:ORrOL5w7JGP4xoDLOvMfYr5r2VI= Xref: csiph.com comp.lang.c:106807 BartC writes: > This line in the 'struct padding' thread: > > for(long i = 0; i > prompted me to do more tests: > > { > double i; // scope 1 > for (int i=0; i<10; ++i) // scope 2 > i; // scope 2 > i; // scope 1, deliberate misalignment > > Is is correct that the 'int i' inside the for-loop header creates a new > scope for the following single statement, even without the existence of > a formal {...} block? Did you try looking it up in the standard before posting? Why not? > I'm just asking because I'm finding it hard to believe that those last > two final 'i' terms switch types with merely an intervening ';'. If your code layout is deliberately misleading, it's going to lead to surprises. Not all scopes are delimited by curly braces. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"