Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: double free Date: Tue, 19 Jul 2016 12:08:39 -0700 Organization: None to speak of Lines: 52 Message-ID: References: <8760sc2aiz.fsf@bsb.me.uk> <57856cf1.441531@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="12450"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+e6/xVkMW6CcEXap5L/k5C" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:4sqLc9y3hrmHOnt5t2z+pOg7Ulg= sha1:ueF67eeLbelG4hBngGCLAylyq+g= Xref: csiph.com comp.lang.c:90625 BartC writes: > On 19/07/2016 18:20, Richard Heathfield wrote: >> On 19/07/16 17:49, BartC wrote: >>> So who determines which is the Right way and the Wrong way? >> >> In this case, the easy-to-type, easy-to-read, easy-to-maintain, >> easy-to-get-right, easy-to-fix-if-you-typed-it-wrong way is the right >> way, and the stupid way is the wrong way. It's not rocket science. > > OK, so /you/ get to call it. As I suspected. Richard gets to express an opinion. It happens to be an opinion I agree with, as do a lot of other people here. > And presumably, if the language /required/ sizeof(...) in all cases, and > I suggested the parentheses weren't always necessary (as it apparently > makes all those things easy), then I'd still be wrong! If the language required parentheses and you said they weren't required, then of course you'd be wrong. Write your code any way you like. If you post it here, be prepared to have it criticized. If you see a use of sizeof without parentheses that would be clearer with them, feel free to point it out. I've seen no such uses other than ones that you've contrived to make your point. This: x = y + z; is perfectly clear to me, and to anyone who's reasonably familiar with C. Someone who has trouble with that might prefer to write: x = (y + z); instead. They're free to do so, but I consider the parentheses unnecessary; in fact they detract from the line's clarity. This: p = malloc(N * sizeof *p); is perfectly clear to me, and to anyone who's reasonably familiar with C. Someone who has trouble with that might prefer to write: p = malloc(N * sizeof(*p)); instead. They're free to do so, but I consider the parentheses unnecessary; in fact they detract from the line's clarity, though not as badly as in the `x = y + z;` case. Adding the extra parentheses is, in my considered opinion, a solution for which there is no problem. -- 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"