K&R-style variadic functions
Jacob Carlborg
doob at me.com
Wed Jul 18 04:59:39 PDT 2012
On 2012-07-18 11:41, Walter Bright wrote:
> Variadic functions, in order to work in C, need at least one parameter
> so that varargs can work.
>
> int foo();
>
> declares a function with an unspecified parameter list, not a variadic
> one. It is specified by a definition somewhere:
>
> int foo(a,b)
> int a;
> int b;
> { ... }
>
> somewhere.
I think I understand now.
> If Dstep encounters the first declaration form, your options are to:
>
> 1. reject it (a perfectly reasonable approach)
>
> 2. treat it as:
>
> int foo(void);
>
> I suggest option 2, which is what C++ does.
Sounds reasonable. I will also provide a flag specifying how this should
be handled.
I actually found library that uses this style of declaration. It's used
in several places in libruby. For example:
void rb_define_virtual_variable(const
char*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
ANYARGS is defined as:
#ifdef __cplusplus
#define ANYARGS ...
#else
#define ANYARGS
#endif
Does that mean that this C++ declaration:
void foo (...);
Is the same as this C declaration?
void foo ();
I'm wondering if the intention is to cast these function pointers to
their correct signature before calling them.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list