va_list

/* unspecified */ va_list; va_list is a complete object type suitable for holding the information needed by the macros va_start, va_copy, va_arg, and va_end. If a va_list instance is created, passed to another function, and used via va_arg in that function, then any subsequent use in the calling function should be preceded by a call to va_end. It is legal to pass a pointer to a va_list object to another function and then use that object after the function returns. References C11 sta

va_end

Defined in header <stdarg.h> void va_end( va_list ap ); The va_end macro performs cleanup for an ap object initialized by a call to va_start or va_copy. va_end may modify ap so that it is no longer usable. If there is no corresponding call to va_start or va_copy, or if va_end is not called before a function that calls va_start or va_copy returns, the behavior is undefined. Parameters ap - an instance of the va_list type to clean up Expanded value (none). Ref

va_copy

Defined in header <stdarg.h> void va_copy( va_list dest, va_list src ); (since C99) The va_copy macro copies src to dest. va_end should be called on dest before the function returns or any subsequent re-initialization of dest (via calls to va_start or va_copy). Parameters dest - an instance of the va_list type to initialize src - the source va_list that will be used to initialize dest Expanded value (none). Example #include <stdio.h> #include

va_arg

Defined in header <stdarg.h> T va_arg( va_list ap, T ); The va_arg macro expands to an expression of type T that corresponds to the next parameter from the va_list ap. Prior to calling va_arg, ap must be initialized by a call to either va_start or va_copy, with no intervening call to va_end. Each invocation of the va_arg macro modifies ap to point to the next variable argument. If va_arg is called when there are no more arguments in ap, or if the type of the next argument i

Variadic functions

Variadic functions are functions (e.g. printf) which take a variable number of arguments. The declaration of a variadic function uses an ellipsis as the last parameter, e.g. int printf(const char* format, ...);. See variadic arguments for additional detail on the syntax and automatic argument conversions. Accessing the variadic arguments from the function body uses the following library facilities: Macros Defined in header <stdarg.h> va_start enables access to variadic funct

Variadic arguments

Variadic functions are functions that may be called with different number of arguments. Only new-style (prototyped) function declarations may be variadic. This is indicated by the parameter of the form ... which must appear last in the parameter list and must follow at least one named parameter. //New-style declaration int printx(const char* fmt, ...); // function declared this way printx("hello world"); // may be called with one printx("a=%d b=%d", a, b); // or more arguments // int printy(.

Value categories

Each expression in C (an operator with its arguments, a function call, a constant, a variable name, etc) is characterized by two independent properties: a type and a value category. Every expression belongs to one of three primary categories: lvalues, function designators, and non-lvalue object expressions (rvalues). Lvalue expressions Lvalue expression is any expression with object type other than the type void, which potentially designates an object (the behavior is undefined if an lvalue

unsigned

Usage unsigned type modifier

Union declaration

A union is a type consisting of a sequence of members whose storage overlaps (as opposed to struct, which is a type consisting of a sequence of members whose storage is allocated in an ordered sequence). The value of at most one of the members can be stored in a union at any one time. The type specifier for a union is identical to the struct type specifier except for the keyword used: Syntax union name(optional) { struct-declaration-list } (1) union name (2) name - the

union

Usage declaration of a union type