#345 Warning in swig generated files for lua

Kris Lamb

warning: cast from 'void*' to 'long unsigned int' loses precision [-fpermissive]

Caused by
unsigned long userData = (unsigned long)lua_touserdata(L,1); / get the userdata address for later /

According to http://stackoverflow.com/questions/1640423/error-cast-from-void-to-int-loses-precision the fix is to use the intptr_t type.

See diff.

1 Attachments


  • Sami Kankaristo

    Sami Kankaristo - 2014-03-25

    There's also a bug report on the same issue:

    On a 64-bit build (Windows & MinGW 64-bit), this is an error and breaks compilation.

    This patch fixes the error, but causes a new warning in the same function:
    warning: format '%lX' expects argument of type 'long unsigned int', but argument 5 has type 'intptr_t {aka long long int}' [-Wformat=]
    snprintf(output, 255, "<%s userdata: %lX>", className, userData);

    This is caused by 64-bit pointers.

  • Sami Kankaristo

    Sami Kankaristo - 2014-03-25

    Just after posting the above comment, I started browsing source code from SWIG's development version (3.0.1).

    SWIG_Lua_class_tostring seems to have been rewritten. It uses void* instead of unsigned long and lua_pushfstring() instead of snprintf().

    I tried the new version, and it fixes the issue! :)

  • William Fulton

    William Fulton - 2014-03-25
    • status: open --> closed
    • assigned_to: William Fulton
    • Group: -->

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks