[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: Does lua really depend on undefined C behavior
From: Roberto Ierusalimschy <roberto () inf ! puc-rio ! br>
Date: 2012-01-27 0:08:05
Message-ID: 20120127000805.GA8778 () inf ! puc-rio ! br
[Download RAW message or body]
> 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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic