Re: Origins of == in C

Bas V._de Bakker <bas@phys.uva.nl>
Wed, 9 Aug 1995 08:35:41 GMT

          From comp.compilers

Related articles
Origins of == in C jpowers@ti.com (1995-07-20)
Re: Origins of == in C D.Chappell@biochem.usyd.edu.au (Doug CHAPPELL) (1995-07-25)
Re: Origins of == in C Brendan.Gowing@cs.tcd.ie (Brendan Gowing) (1995-07-26)
Re: Origins of == in C peter.schurek@banyan.siemens.co.at (1995-07-28)
Re: Origins of == in C schrod@iti.informatik.th-darmstadt.de (1995-07-31)
Re: Origins of == in C jmccarty@spdmail.spd.dsccc.com (1995-08-01)
Re: Origins of == in C det@sw.stratus.com (David Toland) (1995-08-03)
Re: Origins of == in C bas@phys.uva.nl (Bas V._de Bakker) (1995-08-09)
| List of all articles for this month |
Newsgroups: comp.compilers
From: Bas V._de Bakker <bas@phys.uva.nl>
Keywords: C, design
Organization: Compilers Central
References: 95-07-135 95-07-158
Date: Wed, 9 Aug 1995 08:35:41 GMT

Brendan Gowing <Brendan.Gowing@cs.tcd.ie> writes:


> However, I think that a more intrinsic problem raised by C's "=" and
> "==" is the fact that C grammar treats both as operators in an
> expression. If this were not the case and "=" was constrained to use
> in a statement, then C compilers could spot a lot of the problems that
> you are encountering.


Our moderator writes:


> [Wizard C, the predecessor of Turbo C, had an optional warning whenever
> the top-level operator in an if or while was = and it was quite useful.
> Being a lazy typist, I took to writing if(!!(a = b)) { ... -John]


I'm surprised that noone has mentioned the solution of GCC, which I
think is better than the suggestions I've seen here.


"gcc -Wall" or "gcc -Wparentheses" warns if you use


if (a = b) { ... }


and you can shut it up by using


if ((a = b)) { ... }


which IMHO looks a lot less ugly than !!(a = b).


Bas.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.