Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

root/tags/releases/0.99.9/tango/core/Vararg.d

Revision 5248, 2.2 kB (checked in by larsivi, 2 years ago)

Change inout to ref, thanks Christian Kamm

  • Property svn:mime-type set to text/x-dsrc
  • Property svn:eol-style set to native
Line 
1 /**
2  * The vararg module is intended to facilitate vararg manipulation in D.
3  * It should be interface compatible with the C module "stdarg," and the
4  * two modules may share a common implementation if possible (as is done
5  * here).
6  *
7  * Copyright: Public Domain
8  * License:   Public Domain
9  * Authors:   Hauke Duden, Walter Bright
10  */
11 module tango.core.Vararg;
12
13
14 version( GNU )
15 {
16     public import std.stdarg;
17 }
18 else version( LDC )
19 {
20     public import ldc.vararg;
21 }
22 else
23 {
24     /**
25      * The base vararg list type.
26      */
27     alias void* va_list;
28
29
30     /**
31      * This function initializes the supplied argument pointer for subsequent
32      * use by va_arg and va_end.
33      *
34      * Params:
35      *  ap      = The argument pointer to initialize.
36      *  paramn  = The identifier of the rightmost parameter in the function
37      *            parameter list.
38      */
39     void va_start(T) ( out va_list ap, ref T parmn )
40     {
41         ap = cast(va_list) ( cast(void*) &parmn + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) );
42     }
43
44     /**
45      * This function returns the next argument in the sequence referenced by
46      * the supplied argument pointer.  The argument pointer will be adjusted
47      * to point to the next arggument in the sequence.
48      *
49      * Params:
50      *  ap  = The argument pointer.
51      *
52      * Returns:
53      *  The next argument in the sequence.  The result is undefined if ap
54      *  does not point to a valid argument.
55      */
56     T va_arg(T) ( ref va_list ap )
57     {
58         T arg = *cast(T*) ap;
59         ap = cast(va_list) ( cast(void*) ap + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) );
60         return arg;
61     }
62
63     /**
64      * This function cleans up any resources allocated by va_start.  It is
65      * currently a no-op and exists mostly for syntax compatibility with
66      * the variadric argument functions for C.
67      *
68      * Params:
69      *  ap  = The argument pointer.
70      */
71     void va_end( va_list ap )
72     {
73
74     }
75
76
77     /**
78      * This function copied the argument pointer src to dst.
79      *
80      * Params:
81      *  src = The source pointer.
82      *  dst = The destination pointer.
83      */
84     void va_copy( out va_list dst, va_list src )
85     {
86         dst = src;
87     }
88 }
Note: See TracBrowser for help on using the browser.