On Fri, 5 Dec 2008, Stephen Montgomery-Smith wrote:

Nate Eldredge wrote:

int bangbang(int x) { return !!x; }
int ternary(int x) { return x ? 1 : 0; }

Stylewise, I prefer

int notzero(int x) { return x!=0; }

icc -O0 compiles notzero the same as bangbang (better than ternary). tcc produces better code for notzero than the other two. Sun cc without optimization produces slightly better code for notzero than the other two (one jump instead of two). For everything else all three produce equivalent code.

`x && 1' and `x || 0' are some other possibilities.

Anyway, maybe there is something more useful we could all be doing. :)

--

Nate Eldredge
[EMAIL PROTECTED]
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to