Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "C's Biggest Mistake" Date: Thu, 05 Apr 2018 10:55:40 -0700 Organization: None to speak of Lines: 25 Message-ID: References: <9c7013a2-17bd-4f94-a378-1c45151d0d45@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="7bf2a82357868b78051038e61a1f9d6f"; logging-data="22491"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Jr80pCOP9BFcLZ+5rpt/v" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:p5TX8kEO/EyoCCxpmhHYh86eWfg= sha1:up7/QF441vwZbkJaM4YydL9pL+M= Xref: csiph.com comp.lang.c:128792 David Brown writes: [...] > Allowing assignment in an expression is useful for C idioms such as: > > while (c = next_char()) ... Perhaps not the best example. That tests whether next_char() returned '\0'. It's more common to use EOF (typically -1) as a sentinel value. But it's a useful idiom when 0 is used as a sentinel value, for example with a function that returns a pointer. Personally, I'd make the comparison explicit: while ((p = next_pointer()) != NULL) ... but using the implicit comparison to 0/NULL is perfectly valid. [...] -- 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"