Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this macro?

Tags:

c

ruby

ruby-1.8

In ruby.h, there are a lot of function macros defined like this:

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, from my understanding, this function will be like this:

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

Yet, if HAVE_PROPOTYPES==0, the function definition will be like this:

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

I don't understand if this is grammatically correct. How should I understand it?

like image 604
NickWEI Avatar asked Jan 07 '16 08:01

NickWEI


1 Answers

static inline int rb_type(VALUE obj)
      VALUE obj;    # what the hack is this?
{
    ...
}

This is K&R C. Nobody uses it anymore. It has been deprecated for 20 years at least.

Long time ago function definitions were written like this:

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

instead of

int myfunc(int myparam)
{
   ...
}

So HAVE_PROTOTYPES will always be defined on any decent compiler.

like image 185
Jabberwocky Avatar answered Sep 23 '22 02:09

Jabberwocky