Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!ukma!nrl-cmf!ames!amdcad!news From: news@amdcad.AMD.COM (Network News) Newsgroups: comp.lang.misc Subject: Re: Many people's opinions on compu Message-ID: <22977@amdcad.AMD.COM> Date: 21 Sep 88 02:57:34 GMT References: <1433@garth.UUCP> <208100001@s.cs.uiuc.edu> Reply-To: tim@crackle.amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc., Sunnyvale CA Lines: 24 Summary: Expires: Sender: Followup-To: In article <208100001@s.cs.uiuc.edu> carroll@s.cs.uiuc.edu writes: | | | /* Written 8:50 pm Sep 18, 1988 by smryan@garth.UUCP in s.cs.uiuc.edu:comp.lang.misc */ | | In short, if you want p and q, use p&&q. If you want, if p then q else don't | bother with q, just say false, use p?q:false. | /* End of text from s.cs.uiuc.edu:comp.lang.misc */ | | But if the compiler has any brains at all, p && q should be compiled to | the same thing as p?q:false. I don't see what the latter gains you | except to irritate the programmer. No, they shouldn't compile the same. This is because the && operator, when used as an operand in an assignment, must return either 0 or 1. This means that an extra test must occur on the q variable to see if it is zero or not so it can decide to return 0 or 1. The ?: construct, however, can simply return the value of q without testing it. -- Tim Olson Advanced Micro Devices (tim@crackle.amd.com)