# Inits.c confused me

**URL:** <https://www.ruby-forum.com/t/inits-c-confused-me/148911>\
**Category:** Ruby\
**Created:** [September 18, 2008, 10:13am UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911 "2008-09-18T10:13:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![limux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@limux](https://www.ruby-forum.com/u/limux)\
**Post date:** [September 18, 2008, 10:13am UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911/1 "2008-09-18T10:13:37Z")

</div>

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();  
}

---

<div class="post-metadata">

**Author:** ![limux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@limux](https://www.ruby-forum.com/u/limux)\
**Post date:** [September 18, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911/2 "2008-09-18T14:33:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![limux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@limux](https://www.ruby-forum.com/u/limux)\
**Post date:** [September 18, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911/3 "2008-09-18T17:09:25Z")

</div>

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))”?

---

<div class="post-metadata">

**Author:** ![limux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@limux](https://www.ruby-forum.com/u/limux)\
**Post date:** [September 18, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911/4 "2008-09-18T18:44:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![limux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@limux](https://www.ruby-forum.com/u/limux)\
**Post date:** [September 19, 2008, 2:14am UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911/5 "2008-09-19T02:14:49Z")

</div>

I see, thanks Tim!

---

<div class="post-metadata">

**Author:** ![limux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@limux](https://www.ruby-forum.com/u/limux)\
**Post date:** [September 19, 2008, 2:56am UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911/6 "2008-09-19T02:56:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![limux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@limux](https://www.ruby-forum.com/u/limux)\
**Post date:** [September 20, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911/7 "2008-09-20T18:42:50Z")

</div>

On Thu, Sep 18, 2008 at 8:48 PM, Mengjiang Liu  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![limux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@limux](https://www.ruby-forum.com/u/limux)\
**Post date:** [September 22, 2008, 4:28am UTC](https://www.ruby-forum.com/t/inits-c-confused-me/148911/8 "2008-09-22T04:28:12Z")

</div>

Rick Denatale wrote:

> On Thu, Sep 18, 2008 at 8:48 PM, Mengjiang Liu  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)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/](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!
