_argptr woes

Sean Kelly sean at f4.ca
Fri Mar 16 20:10:51 PDT 2007


Sean Kelly wrote:
> Frits van Bommel wrote:
>> kris wrote:
>>> The D spec says:
>>>
>>> "The implementiations of these variadic functions have a special 
>>> local variable declared for them, _argptr, which is a void* pointer 
>>> to the first of the variadic arguments. To access the arguments, 
>>> _argptr must be cast to a pointer to the expected argument type"
>>>
>>>
>>> To me, this means that a D compiler must implement _argptr in these 
>>> terms. Is that indeed the case, Walter? Or is my interpretation 
>>> incorrect?
>>
>> That would seem to be what it means.
>> That would also seem to be a pretty big portability bug in the spec. 
>> On amd64 definitely !is(va_list == void*) :P. (at least for current 
>> GDC, GCC and any other compiler following 
>> http://www.x86-64.org/documentation/abi.pdf)
> 
> Perhaps I'm being thick, but why in the world would a CPU spec need to 
> contain parameter passing rules?  Or even stack frame information?  I 
> can see an OS caring about stack frame, but parameter passing seems like 
> it should be language-dependent.

I just answered my own question.  From the doc:

     No attempt has been made to specify an ABI for languages other than
     C. However, it is assumed that many programming languages will wish
     to link with code written in C, so that the ABI specifications
     documented here apply there too.

So they define an ABI for C to facilitate interoperability across 
compilers.  This is laudable, but it has nothing to do with calling D 
functions.  They also go on to say:

     The standard calling sequence requirements apply only to global
     functions.  Local functions that are not reachable from other
     compilation units may use different conventions. Nevertheless, it is
     recommended that all functions use the standard calling sequence
     when possible.

By the way, this may be a more appropriate reference for D:

     For the C++ ABI we will use the IA-64 C++ ABI and instantiate it
     appropriately.  The current draft of that ABI is available at:
     http://www.codesourcery.com/cxx-abi/


Sean



More information about the Digitalmars-d mailing list