[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Compiler warnings when dealing with huge integers
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sun, 26 Jun 2016 13:27:11 -0300
> A project I'm contributing to gets compiled with -Wfloat-conversion
> and -Wbad-function-cast (and I can't change this). The compiler is
> gcc.
> [...]
> On the other hand, if I write that line as:
>
> off_t a = (off_t)lua_tonumber(L, -1);
>
> I inhibit that warning but get a different one because of the
> -Wbad-function-cast:
>
> " warning: cast from function call of type 'lua_Number {aka double}'
> to non-matching type 'long long int' [-Wbad-function-cast] "
>
> [...]
>
> I know I can solve this problem by doing instead:
>
> lua_Number num = lua_tonumber(L, -1);
> off_t a = (off_t) num;
Maybe a little off-topic, but why would a compiler accept
'(off_t)num' but warn about '(off_t)lua_tonumber(L, -1)', when
both 'num' and the result of 'lua_tonumber' are double?
-- Roberto