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 15:04:42 -0700 Organization: None to speak of Lines: 48 Message-ID: References: <79d68564-6e2e-447d-a73b-7b19d4e8bc66@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="18093"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yaSWMWFYEOqVYfmDVtsZa" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:TfO38uBNbpEiQH8EkTW6zxUf+Xo= sha1:PECqjusRgXyFk8HLWgjQnxMpwxg= Xref: csiph.com comp.lang.c:67635 "Morten W. Petersen" writes: > On 17.08.2015 22:24, David Brown wrote: > [...] >> I agree with Bart that C allows "for" loops that are ugly, can be >> puzzling or unclear, and can easily have hard-to-spot errors. "for >> (;(cond);)" is an example. >> >> But most "for" loops are simple counters: >> >> for (i = 0; i < 10; i++) { ... } >> >> That's clear and simple, and not significantly different from the for >> loops found in most imperative languages. >> >> Changing that to: >> >> i = 0; >> while (i < 10) { >> ... >> i++; >> } >> >> does not make the program clearer or neater, it does not reduce the risk >> of errors or misunderstanding, it does not make the code faster, and it >> does not make the compiler simpler, clearer or faster. It gives no >> benefits whatsoever - except to reduce the language by a single keyword, >> and help those poor souls that get paid per Kloc. > > It is one of the things that can be removed to reduce complexity and > the learning curve of developing a program. Removing the for loop would not reduce the learning curve of developing a program. It would instead remove some very small burden from the compiler developer and place it on the programmer. If I want a loop to run 10 times, setting i to the values 0 through 9 in sequence, a for loop lets me express that intent more clearly than the equivalent while loop, and it's easier and less error-prone to write. That benefit is more than worth the minor cost of (a) defining it in the language and (b) implementing it in compilers. (One could certainly argue that C's for loop should have been designed differently; that's a different manner than omitting it entirely.) -- 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"