#1168 Swig doesn't know 'x' in macro

open
nobody
None
5
2017-10-07
2011-05-26
Bugs Fly
No

For a macro of the form:

#define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4))
#define DEFAULT_LANG CHR('d','f','l','t')

swig generate:

SWIG_Python_SetConstant(d, "DEFAULT_LANG",SWIG_From_int((int)((((d) <<
24)|((f) << 16)|((l) << 8)|(t)))));

Which compiler will spit error as:

: error: invalid operands to binary << (have ‘struct PyObject *’ and ‘int’)
: error: ‘f’ undeclared (first use in this function)
: note: each undeclared identifier is reported only once for each function it appears in
: error: ‘l’ undeclared (first use in this function)
: error: ‘t’ undeclared (first use in this function)

Discussion

  • Olly Betts

    Olly Betts - 2017-10-07

    The other bug was fixed last year in 3.0.11, but this case still fails (though in a different way now):

      SWIG_Python_SetConstant(d, "DEFAULT_LANG",SWIG_From_int(static_cast< int >((( << 24)|( << 16)|( << 8)|))));
    

    It looks like the issue is actually the parentheses around each character literal - if I remove those, then this works. Testing a fix.

    A simpler testcase is:

    %constant DEFAULT_LANG = ('d')<<24;
    
     

Log in to post a comment.