what's the meaning of the macro

D

DaVinci

I had thinked about the implements of variable argument for a long
time.
But I only know a little about it on the following macro.
Could you please explain it for me?
more detail.Thanks very much.

typedef char *va_list;
275 #endif /* _VALIST */
276
277 /*
278 * Storage alignment properties
279 */
280
281 #define _AUPBND (sizeof (acpi_native_int) - 1)
282 #define _ADNBND (sizeof (acpi_native_int) - 1)
283
284 /*
285 * Variable argument list macro definitions
286 */
287
288 #define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
289 #define va_arg(ap, T) (*(T *)(((ap) += (_bnd (T,
_AUPBND))) - (_bnd (T,_ADNBND))))
290 #define va_end(ap) (void) 0
291 #define va_start(ap, A) (void) ((ap) = (((char *) &(A)) +
(_bnd (A,_AUPBND))))
292
 
C

Chris Dollin

DaVinci said:
I had thinked about the implements of variable argument for a long
time.
But I only know a little about it on the following macro.
Could you please explain it for me?
more detail.Thanks very much.

typedef char *va_list;
275 #endif /* _VALIST */
276
277 /*
278 * Storage alignment properties
279 */
280
281 #define _AUPBND (sizeof (acpi_native_int) - 1)
282 #define _ADNBND (sizeof (acpi_native_int) - 1)
283
284 /*
285 * Variable argument list macro definitions
286 */
287
288 #define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
289 #define va_arg(ap, T) (*(T *)(((ap) += (_bnd (T,
_AUPBND))) - (_bnd (T,_ADNBND))))
290 #define va_end(ap) (void) 0
291 #define va_start(ap, A) (void) ((ap) = (((char *) &(A)) +
(_bnd (A,_AUPBND))))
292

It's internal implementation magic, playing with implementation-dependant
properties of the addresses of the arguments to variable-argument
functions.

Unless you /need/ to know what it all means, likely best to
stay away from it. Otherwise it may tempt you to rely on it.

(`va_start` finds the address of the first variable argument,
`va_arg` returns the item at the current address and advances,
`va_end` tidies up if that's necessary.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,812
Messages
2,569,694
Members
45,478
Latest member
dontilydondon

Latest Threads

Top