le_me le_me - 1 year ago 80
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?

Answer Source

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.