|
Hopefully your compiler won't optimize that out, and it's not actually atomic in the sense that it's thread safe :-) Does the more verbose but clear (i ? true : false) generate better or worse code in terms of speed or size? Ralph
No compiler should optimize that out for the very reason that it serves a purpose. It should be faster then the ? : case, as few compilers will output branching code for !! where as many for the ? : case. Still simpler to read, and already present in the Lua core is:
(i != 0) // casts i to a 1 or a 0Which would likely produce code equal to or better than the other two methods on all compilers.
- Alex