lua-users home
lua-l archive

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


David Given wrote:
Roberto Ierusalimschy wrote:
[...]
But it seems that casting (double)-1 to an unsigned int will result in
daemons flying out of our noses.

From my understanding of the specification, that's correct. It will.

It just so happens that on all platforms and all compilers that I know of it
produces the same result as (int)(unsigned int)(double)-1, but that's
coincidental.

(You know, it would be rather informative some time to put together a C
compiler which actually *checked* for all these undefined behaviour cases. I
suspect we might learn something...)

So, to be safe, maybe I should do this?

#define lua_number2integer(i, d) ((d) < 0 ? (i) = (int)(d) : (i) = (int)(unsigned int)(d))

Brian