11.07.2015 Views

CrossWorks for ARM User Guide

CrossWorks for ARM User Guide

CrossWorks for ARM User Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

- Variable argumentsThe header file defines a number of macros to access variable parameterlists.Functionsva_endva_argva_endva_copyStart access to variable argumentsGet variable argument valueFinish access to variable argumentsCopy va_arg structureva_argSynopsisDescription#include type va_arg(va_list ap, type);va_arg expands to an expression that has the specified type and the value of the typeargument. The ap parameter must have been initialized by va_start or va_copy,without an intervening invocation of va_end. You can create a pointer to a va_list andpass that pointer to another function, in which case the original function may makefurther use of the original list after the other function returns.Each invocation of the va_arg macro modifies ap so that the values of successivearguments are returned in turn. The parameter type must be a type name such that thetype of a pointer to an object that has the specified type can be obtained simply bypostfixing a ‘*’ to type.If there is no actual next argument, or if type is not compatible with the type of theactual next argument (as promoted according to the default argument promotions), thebehavior of va_arg is undefined, except <strong>for</strong> the following cases:•one type is a signed integer type, the other type is the corresponding unsignedinteger type, and the value is representable in both types;•one type is pointer to void and the other is a pointer to a character type.The first invocation of the va_arg macro after that of the va_start macro returns thevalue of the argument after that specified by parmN. Successive invocations return thevalues of the remaining arguments in succession.ExamplesWhen calling va_arg, you must ensure that type is the promoted type of the argument,not the argument type. The following will not work as you expect:char x = va_arg(ap, char);Because characters are promoted to integers, the above must be written:278 Chapter 28 Standard C Library Reference

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!