lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Ralph Hempel wrote:
> Hopefully your compiler won't optimize that out, and it's not
> actually atomic in the sense that it's thread safe :-)

The compiler *must not* optimize it out --- that's incorrect code! And I
mean 'atomic' in the this-is-a-fundamental-concept sense, rather than in
the synchronisation sense.

> Does the more verbose but clear (i ? true : false) generate better
> or worse code in terms of speed or size?

Personally, I find that rather less clear --- too wordy and doesn't
adequately encapsulate what it is I'm trying to do. I'd expect any
modern compiler to generate the same code for both. However, optimising
!! is a rather easier job that ?:; the latter is a conditional, and
would require the compiler to recognise the intent of the entire
operation and replace it with equivalent code, whereas optimising !!
merely requires it to know what happens when you perform ! twice.

┌─── ───── ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

Attachment: signature.asc
Description: OpenPGP digital signature