[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Does lua really depend on undefined C behavior
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 26 Jan 2012 22:08:05 -0200
> lua_tounsigned does a cast from float to unsigned int. (I've
> compiled Lua to use float instead of double.) Casting a negative
> float value to unsigned int is undefined according to the C
> standard.
>
> Does Lua really depend on the undefined behavior? Or is the test wrong.
>
> In my case the test listed above fails with lua_tounsigned()
> returning 0 and (lua_Unsigned)-0x1234) returning 4294962636.
Neither. What is broken is the backup implementation of
lua_number2unsigned for non-double numbers. (The default implementation,
for doubles, does not do a cast from double to unsigned int.) You should
provide your own version of that macro.
-- Roberto