le_me le_me - 8 months ago 20
Ruby Question

What does a macro definition with the same token twice in C mean?

I was reading the Ruby source code when I stumbled upon the following:



As far as I can tell
is not defined before. (I grepped the Ruby source recursively).

What does that line do exactly?


This define will expand into the literal token RSTRING_EMBED_LEN_MAX, just as you would expect.

By looking at the source, you'll see, that the macro is used to define an enum value with the same name, set to (int)((sizeof(VALUE)*3)/sizeof(char)-1).

The commit, linked by matt, explains they converted all macros into enums, to improve debugging. And the macro was left for compatibility reasons.