1

Browsing through MRI's code, I found these #defines I don't understand:

#define ROBJECT_EMBED_LEN_MAX ROBJECT_EMBED_LEN_MAX
#define ROBJECT_EMBED ROBJECT_EMBED
enum {
    ROBJECT_EMBED_LEN_MAX = 3,
    ROBJECT_EMBED = RUBY_FL_USER1,

    ROBJECT_ENUM_END
};

What's the point of those #defines? They seem to do nothing...

This code is found in the ruby/include/ruby/ruby.h file in the ruby github repo.

csTroubled
  • 367
  • 1
  • 3
  • 9

1 Answers1

0

The #defines make it possible to test for the existence of the definition at compile-time using #ifdef. (You cannot test for the existence of an enum at compile-time.)

Since the C preprocessor doesn't do recursive substitution, defining a symbol as itself effectively does nothing; the symbol is replaced once with itself, and then passed normally to the compiler.

rici
  • 234,347
  • 28
  • 237
  • 341