strange construct in ruby.h

N

Nick

Just recently tried to look at the ruby source code and I came across
some constructs that were unfamiliar for me, example:

void rb_secure_update _((VALUE));

Looks like a standard function declaration but before the arguments
there is an underscore. What is that about? Does not look like any
C-construct I have seen, (been programming C for 4 years).

Any information appreciated.

Thanks, Nick
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Just recently tried to look at the ruby source code and I came across
some constructs that were unfamiliar for me, example:

void rb_secure_update _((VALUE));

Looks like a standard function declaration but before the arguments
there is an underscore. What is that about?

It is likely a macro (a "#define _(....) ....")
and the macro isn't something covered by the C standard.

Does not look like any
C-construct I have seen, (been programming C for 4 years).

Yah. It is typical of some extensions.



- --

Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFET5CkagVFX4UWr64RAu0BAKDWP6AU4c2tuG+L25s365I/NC3rOQCg0T3/
OBoA0qk7GCs2pBpEQ1KFFaE=
=sZ6c
-----END PGP SIGNATURE-----
 
R

Roberto Waltman

Nick said:
Just recently tried to look at the ruby source code and I came across
some constructs that were unfamiliar for me, example:

void rb_secure_update _((VALUE));

Looks like a standard function declaration but before the arguments
there is an underscore. What is that about? Does not look like any
C-construct I have seen

Guess #1: Some evil mind defined '_' as a macro expanding to a
different parameter list?
(This should be added to the list in "How to write unmaintainable
code")
Guess #2: A non-standard compiler extension. Check the docs.
 
W

Walter Roberson

Just recently tried to look at the ruby source code and I came across
some constructs that were unfamiliar for me, example:
void rb_secure_update _((VALUE));
Looks like a standard function declaration but before the arguments
there is an underscore. What is that about? Does not look like any
C-construct I have seen, (been programming C for 4 years).

Likely _ is a macro that expands to () if the header cannot prove
that prototypes are supported, and which expands to its argument
if the header knows that prototypes are supported. The inner layer of ()
is there to force the argument list to all be considered as one argument
for preprocessor purposes, as the preprocessor does not offer a way
[in C89 anyhow] to define macros that take varying numbers of arguments.
 
E

Eric Sosman

Nick wrote On 04/26/06 11:16,:
Just recently tried to look at the ruby source code and I came across
some constructs that were unfamiliar for me, example:

void rb_secure_update _((VALUE));

Looks like a standard function declaration but before the arguments
there is an underscore. What is that about? Does not look like any
C-construct I have seen, (been programming C for 4 years).

Hunt through the rest of the header files, and you
will almost certainly discover that _ is a macro. You'll
also probably find that the macro definition depends on
whether __STDC__ is defined, or on some similar indication
that the compiler is old enough to apply for a driving
license.

Function argument prototypes were added to the C language
in 1989 with the adoption of the ANSI Standard, and were
not supported by most compilers that existed before that time.
The _ macro will quite likely turn out to be a dodge that
generates a prototype if the compiler is young enough to
support them, but generates just () if it's too old.
 
N

niklasalverup

Found this in another .h file, mystery solved.

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

Thanks everybody for your input.

/Nick
 

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,183
Messages
2,570,965
Members
47,511
Latest member
svareza

Latest Threads

Top