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: Sat, 23 Jul 2016 20:55:21 -0700 Organization: None to speak of Lines: 83 Message-ID: References: <87shvfyrq6.fsf@bsb.me.uk> <5793313b.2453031@news.xs4all.nl> <87fur0acpk.fsf@bsb.me.uk> <4b97df6b-97ec-4ce8-a263-cbc75f84d335@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="7541"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wjlec/mEuQOpUmXozF27b" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:Llmh0SQo7ybAQycXBHq31tL8gfs= sha1:aJXSWiWDDHmgF7dD3IgbNccibFw= Xref: csiph.com comp.lang.c:90888 luser droog writes: > On Saturday, July 23, 2016 at 4:17:18 PM UTC-5, Keith Thompson wrote: >> BartC writes: >> > On 23/07/2016 20:51, Keith Thompson wrote: >> [...] >> >> I do not recall Tim saying that this implies one should not use >> >> parentheses for clarity. Do you? >> > >> > He said (referring to knowing all binary op precedence levels): >> > >> > "I would. And do. And happy to do it. If you can't take >> > the heat, stay out of the kitchen." >> > >> > So he knows exactly what every expression means, and suggests that only >> > those who also know all the levels should be coding. So why would anyone >> > need extra parentheses? Either something is already clear, or you >> > shouldn't be programming. >> >> Was that intended to answer my question? I believe you are inferring >> things he didn't say. > > I know Tim will answer for himself in due time, but in the interest of > time here's what I recall from when this came up a few months ago. > This was close on the heels of a very comprehensive and insightful > multi-review of my interpreter for a new APL-like language so I was > in the mindset to absorb all available wisdom from his pen to a > degree perhaps unique among the readers here. > > What he said (IIRC) was ditch the parens and use spaces. You should > know (or being willing to learn) the relative precedences of the > operators that you use in an expression. And you should use spaces > to demonstrate what you (the programmer) intend. > > Much of my code runs afoul of this prescription. But I'm making efforts. > > For an example of this "style", you should write > > x = y*z + w; > > instead of > > x = (y*z)+w; > > or even > > x = (y * z) + w; > > The first version should match more nicely with the equations in your > notebook. Thank you, but I don't think that really answers the question I was asking, or at least the one I meant to ask. The fact that "*" binds more tightly than "+" is likely to be obvious even to someone who's not familiar with C. I likely wouldn't use parentheses in that case myself. I might not even bother with spacing: x = y * z + w; > I don't venture a `sizeof` example because I haven't done my homework > there, yet. A more relevant example might be: x | y ^ z That expression is entirely unambiguous as far as the C standard is concerned. Tim would argue that a C programmer would know that it's equivalent to x | (y ^ z) and in principle I agree, but I couldn't have written this if I hadn't looked it up just now. (I even wrote a test program just to be sure I don't screw up on operator precedence in a discussion of operator precedence.) (I *know* all the operator precedences. It just happens that I keep some of that knowledge outside my head.) I would certainly advocate using parentheses in that case. BartC inferred that Tim would recommend *not* using parentheses. -- 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"