Path: chuka.playstation.co.uk!tjs From: tjs@cs.monash.edu.au (Toby Sargeant) Newsgroups: scee.yaroze.beginners Subject: Re: Collision Detection!.....(Joy) Date: 24 Jun 1999 23:43:51 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 23 Message-ID: References: <7kdntq$4fj13@chuka.playstation.co.uk> <376d3500.12938268@www.netyaroze-europe.com> <7kqf2d$qpv1@chuka.playstation.co.uk> <7kruf5$qpv9@chuka.playstation.co.uk> <3772b870.14958289@www.netyaroze-europe.com> NNTP-Posting-Host: longford.cs.monash.edu.au X-Newsreader: slrn (0.9.4.3 UNIX) On Thu, 24 Jun 1999 23:05:10 GMT, Barry & Robert Swan wrote: >My thanks to the wierd guy at Sony who left a !! in some code that we >looked at, and made us wonder what the hell he was doing...! !!val and val?1:0 both produce the same i386 and sparc assembler under optimisation. I'm going to assume that this means that the RTL produced is the same, which would mean that this holds true for MIPS as well. I'm at work, though, so I can't test this out. This means that !!val is cute, but a) relies on true=1 (which is not _required_; any non zero value will do - although the ANSI standard probably specifies that it must be 1, just to stop freakish bugs in code like this) and b) is a lot less readable than val?1:0, which is very explicit about what it's actually doing. The other issue is also the fact that ! binds more strongly than ?, so !!(val+1) requires brackets, whereas i+1?1:0 does what is expected (unless you're using Visual C++, which, last time I checked, got the precedence of the ternary operator wrong). Toby.