Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!bbn!oberon!nunki.usc.edu!jeenglis From: jeenglis@nunki.usc.edu (Joe English) Newsgroups: comp.lang.c Subject: Re: Definition of boolean type Message-ID: <2892@nunki.usc.edu> Date: 1 Mar 89 22:40:28 GMT References: <10@dbase.UUCP> <1989Feb10.092449.20875@sq.uucp> <6849@pogo.GPID.TEK.COM> <9753@smoke.BRL.MIL> Reply-To: jeenglis@nunki.usc.edu (Joe English) Organization: University of Southern California, Los Angeles, CA Lines: 39 gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <6849@pogo.GPID.TEK.COM> rickc@pogo.GPID.TEK.COM (Rick Clements) writes: >>With the compiler I am currently using, I use "if (x == FALSE)" or >>"if (x != FALSE). ... The compiler I am using generates LESS code >>this way. ("if (x)" causes it to go to the work of converting it to >>a 1 or 0 with some less than efficient code. > >That's pretty strange -- "if(x)" means no more and no less than >"if x is nonzero", which nearly all instruction sets support directly. >It's easy to imagine a dumb compiler that produces MORE code for >"if(x!=0)" but not one that produces LESS code. I once had to work with a compiler that was broken in a similar way: boolean expressions would calculate either a 0 or a 1, then test that result and branch accordingly. This generated *three unnecessary instructions* for every relational expression. (And the fourth pass of the compiler was called the "optimizer!" I don't think it did a very good job of optimizing...) If I recall correctly, it generated the same amount of code for "if(x)" and "if(x!=0)," but it went something like: Compare x and zero; move 1 into AX; if test yielded equal, skip next instruction; move 0 into AX; Then it would do an "OR AX,AX" and branch accordingly. Shocking, but true. Before you ask (so you can avoid purchasing it :-), the compiler in question is an old (c. 1984) version of Computer Innovation's C86, I think somewhere around version 1.2. --Joe English jeenglis@nunki.usc.edu