Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: C pointer semantics with dynamically allocated struct Date: Mon, 17 Aug 2015 12:11:44 -0700 Organization: None to speak of Lines: 59 Message-ID: References: <87d1ys5gmr.fsf@bsb.me.uk> <003ef111-3124-49dc-b5cc-4d1bc0cc258c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="3302"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AxAi0cOoeR6bDnq2THTqn" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:PiIkbFXgzpR6+DP/VCAijzaIfwA= sha1:DXCKs5x6GSHkGcJ8q5m/zRovpAY= Xref: csiph.com comp.lang.c:67612 Bartc writes: > On 17/08/2015 17:45, Keith Thompson wrote: >> Bartc writes: >>> On 17/08/2015 02:47, glen herrmannsfeldt wrote: >> [...] >>>> I pretty much never write while loops. If I have logic that would >>>> need one, I write the matching for loop instead. >>> >>> That sounds rather perverse. How you thought about whether that makes it >>> easier or harder for the readers of your code? >> >> I agree, but ... >> >>> I've just looked at some of my code and I use many hundreds of while >>> statements, each of which exactly represents what I'm trying to express. >>> Example: >>> >>> while(a>> >>> I can't really see that it helps matters by writing it as: >>> >>> for (;a> >> Why did you put the "a=a*2" in the header of the for loop? > > Why not? It's the sort of thing that would be done by people who like to > cram everything into a for-loop. How did "people who like to cram everything into a for-loop" enter into the discussion? It almost seems as if you're trying to make the for loop as terse and obscure as possible to make some point about C's for loops. > What exactly belongs in that third part of a for-loop anyway? 'a' is > being tested as the exit condition, and it is a that is being updated to > its next value. It's hard to see the intent without more context, but the behavior of the original while loop: while(a 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"