lua-users home
lua-l archive

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


> 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