Inits.c confused me

i am reading the ruby source, but the follow inits.c confused me.
please give some advices, thanks!

what’s meaning of the “Init_Array _((void));”?
is it a funtion declare or a macro?
/**********************************************************************

inits.c -

$Author: dave $
$Date: 2003/12/19 03:58:57 $
created at: Tue Dec 28 16:01:58 JST 1993

Copyright © 1993-2003 Yukihiro M.

**********************************************************************/

#include “ruby.h”

void Init_Array _((void));
void Init_Bignum _((void));
void Init_Binding _((void));
void Init_Comparable _((void));
void Init_Dir _((void));
void Init_Enumerable _((void));
void Init_Exception _((void));
void Init_syserr _((void));
void Init_eval _((void));
void Init_load _((void));
void Init_Proc _((void));
void Init_Thread _((void));
void Init_File _((void));
void Init_GC _((void));
void Init_Hash _((void));
void Init_IO _((void));
void Init_Math _((void));
void Init_marshal _((void));
void Init_Numeric _((void));
void Init_Object _((void));
void Init_pack _((void));
void Init_Precision _((void));
void Init_sym _((void));
void Init_process _((void));
void Init_Random _((void));
void Init_Range _((void));
void Init_Regexp _((void));
void Init_signal _((void));
void Init_String _((void));
void Init_Struct _((void));
void Init_Time _((void));
void Init_var_tables _((void));
void Init_version _((void));

void
rb_call_inits()
{
Init_sym();
Init_var_tables();
Init_Object();
Init_Comparable();
Init_Enumerable();
Init_Precision();
Init_eval();
Init_String();
Init_Exception();
Init_Thread();
Init_Numeric();
Init_Bignum();
Init_syserr();
Init_Array();
Init_Hash();
Init_Struct();
Init_Regexp();
Init_pack();
Init_Range();
Init_IO();
Init_Dir();
Init_Time();
Init_Random();
Init_signal();
Init_process();
Init_load();
Init_Proc();
Init_Binding();
Init_Math();
Init_GC();
Init_marshal();
Init_version();
}

Mengjiang Liu wrote:

i am reading the ruby source, but the follow inits.c confused me.
please give some advices, thanks!

what’s meaning of the “Init_Array _((void));”?
is it a funtion declare or a macro?

It’s a function declaration. Init_Array is an external function that is
defined in array.c.

Tim H. wrote:

Mengjiang Liu wrote:

i am reading the ruby source, but the follow inits.c confused me.
please give some advices, thanks!

what’s meaning of the “Init_Array _((void));”?
is it a funtion declare or a macro?

It’s a function declaration. Init_Array is an external function that is
defined in array.c.
since It’s a function declaration, and in array.c the init_array define
as
“void init_array()”, why not write as “static void init_array();”, but
“void Init_Array ((void))"? what’s the meaning of "((void))”?

Mengjiang Liu wrote:

Tim H. wrote:

Mengjiang Liu wrote:

i am reading the ruby source, but the follow inits.c confused me.
please give some advices, thanks!

what’s meaning of the “Init_Array _((void));”?
is it a funtion declare or a macro?

It’s a function declaration. Init_Array is an external function that is
defined in array.c.
since It’s a function declaration, and in array.c the init_array define
as
“void init_array()”, why not write as “static void init_array();”, but
“void Init_Array ((void))"? what’s the meaning of "((void))”?

_ is a macro that is defined in defines.h. It’s purpose is to support
very old compilers that don’t support prototypes. If the compiler
support prototypes, then

void Init_Array _((void));

expands to

void Init_Array(void);

If the compiler does not support prototypes, it expands to

void Init_Array();

#undef _
#ifdef HAVE_PROTOTYPES

define _(args) args

#else

define _(args) ()

#endif

I see, thanks Tim!

5.26 Prototypes and Old-Style Function Definitions

GNU C extends ISO C to allow a function prototype to override a later
old-style non-prototype definition. Consider the following example:

 /* Use prototypes unless the compiler is old-fashioned.  */
 #ifdef __STDC__
 #define P(x) x
 #else
 #define P(x) ()
 #endif

 /* Prototype function declaration.  */
 int isroot P((uid_t));

 /* Old-style function definition.  */
 int
 isroot (x)   /* ??? lossage here ??? */
      uid_t x;
 {
   return x == 0;
 }

Suppose the type uid_t happens to be short. ISO C does not allow this
example, because subword arguments in old-style non-prototype
definitions are promoted. Therefore in this example the function
definition’s argument is really an int, which does not match the
prototype argument type of short.

This restriction of ISO C makes it hard to write code that is portable
to traditional C compilers, because the programmer does not know whether
the uid_t type is short, int, or long. Therefore, in cases like these
GNU C allows a prototype to override a later old-style definition. More
precisely, in GNU C, a function prototype argument type overrides the
argument type specified by a later old-style definition if the former
type is the same as the latter type before promotion. Thus in GNU C the
above example is equivalent to the following:

 int isroot (uid_t);

 int
 isroot (uid_t x)
 {
   return x == 0;
 }

GNU C++ does not support old-style function definitions, so this
extension is irrelevant.

On Thu, Sep 18, 2008 at 8:48 PM, Mengjiang Liu
[email protected]wrote:

5.26 Prototypes and Old-Style Function Definitions

GNU C extends ISO C to allow a function prototype to override a later
old-style non-prototype definition. Consider the following example:

I believe that the Ruby source needs to compile with compilers besides
gcc,
So GNU C extensions aren’t useful.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Rick Denatale wrote:

On Thu, Sep 18, 2008 at 8:48 PM, Mengjiang Liu
[email protected]wrote:

5.26 Prototypes and Old-Style Function Definitions

GNU C extends ISO C to allow a function prototype to override a later
old-style non-prototype definition. Consider the following example:

I believe that the Ruby source needs to compile with compilers besides
gcc,
So GNU C extensions aren’t useful.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/
now i known the _((void)) is a macro. another question if there is a
space between InitArray(void) when it is expended. in other words, is it
expended to “InitArray(void)” or “InitArray (void)”?

thks!