K&R-style variadic functions
Regan Heath
regan at netmail.co.nz
Thu Jul 19 02:38:41 PDT 2012
On Thu, 19 Jul 2012 08:33:12 +0100, Paulo Pinto <pjmlp at progtools.org>
wrote:
> On Wednesday, 18 July 2012 at 20:13:10 UTC, Walter Bright wrote:
>> On 7/18/2012 11:47 AM, Jacob Carlborg wrote:
>>> On 2012-07-18 20:43, Walter Bright wrote:
>>>> On 7/18/2012 4:59 AM, Jacob Carlborg wrote:
>>>>> Does that mean that this C++ declaration:
>>>>>
>>>>> void foo (...);
>>>>
>>>> Not allowed in C or C++.
>>>
>>> When compiling in C++ mode, both Clang and GCC accepts this.
>>
>> How would you get the arguments inside foo?
>
> As described here,
>
> http://pubs.opengroup.org/onlinepubs/7908799/xsh/varargs.h.html
That /requires/ an argument in the definition (AFAIKS), e.g.
execl(va_alist) <- va_alist is the argument name
va_dcl <- this is #define va_dcl va_list va_alist;
{
}
so, it's no different to any other old-style function, e.g.
foo(a)
int a;
{
}
Now.. the declaration may be a different story. These would be valid
declarations for the above:
void execl(); <- no parameters necessary in a declaration
void foo(); <- no parameters necessary in a declaration
It may be that GCC allows a declaration of:
void execl(...);
But I wasn't ware that was valid ANSI C, perhaps it's a GCC/clang
feature? Can anyone find docs on it?
If we /assume/ the above declaration always refers to a function with a
definition of:
execl(va_alist)
va_dcl
{
}
Then we assume the first argument is /always/ going to be a 32 bit value
(int, or 32 bit pointer) then we could speculatively convert to this D
extern (C) void execl(int first, ...);
But, if either assumption is false this would probably crash when used.
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list