What is this macro?

There ruby.hare many function macros defined as follows:

static inline int
    #if defined(HAVE_PROTOTYPES)
    rb_type(VALUE obj)
    #else
    rb_type(obj)
       VALUE obj;
    #endif
    {
        if (FIXNUM_P(obj)) return T_FIXNUM;
        if (obj == Qnil) return T_NIL;
        if (obj == Qfalse) return T_FALSE;
        if (obj == Qtrue) return T_TRUE;
        if (obj == Qundef) return T_UNDEF;
        if (SYMBOL_P(obj)) return T_SYMBOL;
        return BUILTIN_TYPE(obj);
    }

If HAVE_PROTOTYPES==1, in my opinion, this function will look like this:

static inline int rb_type(VALUE obj)
{
   ...
}

However, if HAVE_PROPOTYPES==0, the definition of the function is as follows:

static inline int rb_type(VALUE obj)
      VALUE obj;
{
    ...
}

I do not understand if this is grammatically correct. How should I understand that?

+4
source share
1 answer
static inline int rb_type(VALUE obj)
      VALUE obj;    # what the hack is this?
{
    ...
}

This is K & R C. No one else uses it. It has been out of date for at least 20 years.

For a long time, function definitions were written as follows:

int myfunc(myparam)
  int myparam;
{
   ...
}

instead

int myfunc(int myparam)
{
   ...
}

So, HAVE_PROTOTYPESit will always be defined on any decent compiler.

+8
source

Source: https://habr.com/ru/post/1623218/


All Articles