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
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))”?
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
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/
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!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.