开发者

C underscore prototype syntax

I was trying to compile a ruby module, and my compiler开发者_如何转开发 choked. I think it might have something to do with a line in ruby.h:

void rb_check_type _((VALUE,int));

I've never seen this _ syntax before. What does it mean? Could it cause problems for my compiler (Visual Studio)?


It strongly looks like a macro invocation with a macro named '_'. Its the double-parens that are the giveaway. You usually only see that in calls to complex macros that want to be able to generate function calls with arbitrary numbers of parameters.

So, the various possibilities would seem to be:

  1. The macro shouldn't be called '_' and something has damaged that line. Maybe rb_check_type_ is the correct name of the macro. Maybe something else is. Look for similar calls and see how they differ.
  2. The macro really is '_' and its not being defined for some reason. That would depend on the header files you include. Have you, perhaps, forgotten one?
  3. The macro exists and really is '_' but its expanding to something wrong. That could be checked by looking at the macro-expanded output of the compiler. Most compilers have a way to request that.

I can't really give you any more advice than that as you didn't give any specifics as to what error was actually produced by your compiler.


The macro is really named '_' in ruby.h (or a subordinately called .h of ruby.h). What's worse is that other packages do the same thing e.g. wxWidgets. Under g++ 3.3 one could:

    #include "ruby.h"
    #undef _
    #include "wx/filename.h"

and the compiled output would use wxWidget's version of _ (which happened to work for me), but under g++ 4.6.1 the #undef completely undefines _ in spite of the #undef occuring before the wxWidgets include. This means:

  1. I cannot turn off ruby's _ without turning off wx's _
  2. I cannot leave ruby's _ on without breaking how wx functions run

The solution seems unclear without both parties getting away from macros. I have not found a way with using namespaces in my own code to get around this - still trying...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜