From: Robert L. t. G. <rh...@as...> - 2009-03-10 21:53:33
|
I pointed out that swig doesn't strip comments in macros, which can lead to surprising bugs. William points out that using C83 /* comments */ avoids the problem, but I still think that this is unhelpful behaviour; what would we lose by stripping comments? Users assume that swig understands // comments, so it's surprising that it doesn't in this case. R > To me it is doing the right thing. %GOO(float) expands to (where \n > is a newline): > \nfloat x;\n > > So %FOO(%GOO(float)) is then: > \n// \nfloat x;\n ABC\n > > If you run swig -E, you'll see the resulting output, eg using this: > /*start*/%FOO(%GOO(float));/*end*/ > > you'll get: > > /*start*//*@SWIG:example.i,10,%FOO@*/ > // /*@SWIG:example.i,6,%GOO@*/ > float x; > /*@SWIG@*/ ABC > /*@SWIG@*/;/*end*/ > > Consider using C comments rather than C++ comments as that will give > you what you want. This will clearly work; it's what you have to do in CPP macros too. > Robert Lupton the Good wrote: >> The following .i file generates a syntax error; remove the comment >> in %FOO >> and all is well. It's something about expanding an argument within a >> comment, and I'd guess that the result of expanding %GOO includes >> the newline >> (which is usually what you want) --- so the ABC appears on a line >> of its own. >> If I'm right, we should strip comments before expanding macro >> arguments. >> R >> %module foo; >> %define %GOO(ARG1) >> ARG1 x; >> %enddef >> %define %FOO(ARG2) >> // ARG2 ABC >> %enddef >> %FOO(%GOO(float)); > |