www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to convert va_start macro to D function?

reply V <v pathlink.com> writes:
How can I convert this to D?

#define va_start(ap,v)  ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
Apr 01 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Fri, 01 Apr 2005 20:39:24 -0800, V wrote:

 How can I convert this to D?
 
 #define va_start(ap,v)  ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )

Generally speaking, you don't. You use the template va_arg which is found in the std.stdarg.d module. <code> /* * Placed in public domain. * Written by Hauke Duden and Walter Bright */ /* This is for use with variable argument lists with extern(D) linkage. */ module std.stdarg; alias void* va_list; template va_arg(T) { T va_arg(inout va_list _argptr) { T arg = *cast(T*)_argptr; _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)); return arg; } } </code> -- Derek Parnell Melbourne, Australia 2/04/2005 4:58:48 PM
Apr 01 2005
parent V <v pathlink.com> writes:
Thanks Derek,  I found va_start defined in std.c.stdarg

I hadn't seen it on the website but from now on, I'll just look in the 
actual src folders. :D

V

Derek Parnell wrote:
 On Fri, 01 Apr 2005 20:39:24 -0800, V wrote:
 
 
How can I convert this to D?

#define va_start(ap,v)  ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )

Generally speaking, you don't. You use the template va_arg which is found in the std.stdarg.d module. <code> /* * Placed in public domain. * Written by Hauke Duden and Walter Bright */ /* This is for use with variable argument lists with extern(D) linkage. */ module std.stdarg; alias void* va_list; template va_arg(T) { T va_arg(inout va_list _argptr) { T arg = *cast(T*)_argptr; _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)); return arg; } } </code>

Apr 02 2005