[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

inits.c confused me

Mengjiang Liu

9/18/2008 8:06:00 AM

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 (C) 1993-2003 Yukihiro Matsumoto

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

#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();
}
--
Posted via http://www.ruby-....

7 Answers

Tim Hunter

9/18/2008 12:26:00 PM

0

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.
--
Posted via http://www.ruby-....

Mengjiang Liu

9/18/2008 3:02:00 PM

0

Tim Hunter 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))"?

--
Posted via http://www.ruby-....

Tim Hunter

9/18/2008 4:37:00 PM

0

Mengjiang Liu wrote:
> Tim Hunter 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
--
Posted via http://www.ruby-....

Mengjiang Liu

9/19/2008 12:07:00 AM

0

I see, thanks Tim!
--
Posted via http://www.ruby-....

Mengjiang Liu

9/19/2008 12:49:00 AM

0

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.

--
Posted via http://www.ruby-....

Rick DeNatale

9/20/2008 4:31:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Thu, Sep 18, 2008 at 8:48 PM, Mengjiang Liu <liumengjiang@gmail.com>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.denh...

Mengjiang Liu

9/22/2008 2:20:00 AM

0

Rick Denatale wrote:
> On Thu, Sep 18, 2008 at 8:48 PM, Mengjiang Liu
> <liumengjiang@gmail.com>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.denh...
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!
--
Posted via http://www.ruby-....