C Preprocessor - why _((unsigned LONG_LONG))

R

rett

Hello list,

Can anyone tell me the purpose of the _((my_type)) construct using the
c preprocessor. Below is the the context in which it was used.

VALUE rb_int2inum _((long));
#define INT2NUM(v) rb_int2inum(v)
#define LONG2NUM(v) INT2NUM(v)

Thanks a lot!
 
M

Morris Keesan

Can anyone tell me the purpose of the _((my_type)) construct using the
c preprocessor. Below is the the context in which it was used.

VALUE rb_int2inum _((long));

This was a somewhat common construct about 20 years ago, when not all
C compilers supported function prototypes. Some file which would be
#included before this would define _(x) as either x or as nothing,
depending on whether prototypes were supported. So if everything
were configured properly, the above would come out of the preprocessor
looking either like

VALUE rb_int2inum();

or

VALUE rb_int2inum(long);
 
I

Ike Naar

This was a somewhat common construct about 20 years ago, when not all
C compilers supported function prototypes. Some file which would be
#included before this would define _(x) as either x or as nothing,

Nit: define _(x) as either x or as ()
 
F

Flash Gordon

Ike said:
Nit: define _(x) as either x or as ()

Not quite, you would want it to yield (x) rather than x (for the other
case) as otherwise you would end up with
VALUE rb_int2inum long;
I doubt the compiler would be too happy with this!

The above is, of course, what you are trying to achieve :)
 
M

Morris Keesan

Not quite, you would want it to yield (x) rather than x (for the other
case) as otherwise you would end up with
VALUE rb_int2inum long;

No, Ike was right and I was wrong.

If prototypes are enabled, you want the macro to yield x.
Note that the usage of the macro always has double parens,
so x is always a parenthesized list. In the example code, the argument
to the macro is (long), not long.

If we didn't use the double parens, then there would be an argument-count
error
in using the macro any time the function takes more than one argument.

When _(x) yields x then
this works: char *strcpy _((char *dst, char *src))
but this doesn't: char *strcpy _(char *dst, char *src)
 
R

rett

Nit: define  _(x)  as either  x  or as  ()

Ah, I see. This is the related code for the above example. I wasn't
thinking that underscore by itself was a valid macro. Makes perfect
sense.

#ifdef HAVE_PROTOTYPES
# define _(args) args
#else
# define _(args) ()
#endif

Thanks for you help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top