plibsys
Macros
pstdarg.h File Reference

Variable arguments. More...

#include <pmacros.h>
#include <ptypes.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
Include dependency graph for pstdarg.h:

Go to the source code of this file.

Macros

#define p_va_list   va_list
 Opaque type holding variable number of arguments navigation. More...
 
#define p_va_start(ap, last)   va_start(ap, last)
 Initializes navigation through a variable number of arguments. More...
 
#define p_va_arg(ap, type)   (type) va_arg(ap, type)
 Gets the next argument in the list. More...
 
#define p_va_end(ap)   va_end(ap)
 Ends the navigation. More...
 
#define p_va_copy(dst, src)   ((void) memcpy (&(dst), &(src), sizeof (va_list)))
 Copies a navigation object. More...
 
#define pint8_va_arg(ap)   ((pint8) p_va_arg(ap, pint))
 Unstacks a pint8 variable. More...
 
#define puint8_va_arg(ap)   ((puint8) p_va_arg(ap, puint))
 Unstacks a puint8 variable. More...
 
#define pint16_va_arg(ap)   ((pint16) p_va_arg(ap, pint))
 Unstacks a pint16 variable. More...
 
#define puint16_va_arg(ap)   ((puint16) p_va_arg(ap, puint))
 Unstacks a puint16 variable. More...
 
#define pint32_va_arg(ap)   ((pint32) p_va_arg(ap, pint))
 Unstacks a pint32 variable. More...
 
#define puint32_va_arg(ap)   ((puint32) p_va_arg(ap, puint))
 Unstacks a puint32 variable. More...
 
#define pint64_va_arg(ap)   (p_va_arg(ap, pint64))
 Unstacks a pint64 variable. More...
 
#define puint64_va_arg(ap)   (p_va_arg(ap, puint64))
 Unstacks a puint64 variable. More...
 
#define ppointer_va_arg(ap)   (p_va_arg(ap, ppointer))
 Unstacks a ppointer variable. More...
 
#define pconstpointer_va_arg(ap)   (p_va_arg(ap, pconstpointer))
 Unstacks a pconstpointer variable. More...
 
#define pboolean_va_arg(ap)   ((pboolean) p_va_arg(ap, pint))
 Unstacks a pboolean variable. More...
 
#define pchar_va_arg(ap)   ((pchar) p_va_arg(ap, pint))
 Unstacks a pchar variable. More...
 
#define pshort_va_arg(ap)   ((pshort) p_va_arg(ap, pint))
 Unstacks a pshort variable. More...
 
#define pint_va_arg(ap)   (p_va_arg(ap, pint))
 Unstacks a pint variable. More...
 
#define plong_va_arg(ap)   (p_va_arg(ap, plong))
 Unstacks a plong variable. More...
 
#define puchar_va_arg(ap)   ((puchar) p_va_arg(ap, puint))
 Unstacks a puchar variable. More...
 
#define pushort_va_arg(ap)   ((pushort) p_va_arg(ap, puint))
 Unstacks a pushort variable. More...
 
#define puint_va_arg(ap)   (p_va_arg(ap, puint))
 Unstacks a puint variable. More...
 
#define pulong_va_arg(ap)   (p_va_arg(ap, pulong))
 Unstacks a pulong variable. More...
 
#define pfloat_va_arg(ap)   ((pfloat) p_va_arg(ap, pdouble))
 Unstacks a pfloat variable. More...
 
#define pdouble_va_arg(ap)   (p_va_arg(ap, pdouble))
 Unstacks a pdouble variable. More...
 

Detailed Description

Variable arguments.

Author
Jean-Damien Durand

Functions declared with a variable number of arguments use macros to step through them.

The p_va_list type must be declared in such function, p_va_start, p_va_arg and p_va_end are used to initialize, to step through and to end the navigation, respectively.

A variable number of arguments can be propagated to another function which accepts a p_va_list parameter, using p_va_copy.

Any use of p_va_start or p_va_copy must have a corresponding p_va_end.

Using a variable number of parameters requires a known-in-advance contract between the caller and the callee on the number of parameters and their types. Note, that this mechanism is a weakly typed: the compiler will always apply default type promotion, regardless if you explicitely typecast an argument in the stack, i.e.:

You need to be very careful when using variable arguments. Improper usage may lead to program crash. In order to avoid type casting mistakes, consider using macros for variable arguments with explicit type casting provided below. Though you still can use p_va_arg if you know what are you doing.

Please note, that stdarg.h implementation is not compatible with varargs.h, and only one of them should be used in a compilation unit. You must be sure that you don't use varargs.h along with the current implmenetation, otherwise runtime failures are inevitable.

Macro Definition Documentation

◆ p_va_arg

#define p_va_arg (   ap,
  type 
)    (type) va_arg(ap, type)

Gets the next argument in the list.

Parameters
apDeclared object of type va_list, previously initalized with p_va_start.
typeType of the next argument.
Returns
Value of the next argument.
Since
0.0.4

◆ p_va_copy

#define p_va_copy (   dst,
  src 
)    ((void) memcpy (&(dst), &(src), sizeof (va_list)))

Copies a navigation object.

Parameters
dstDestination object of type p_va_list.
srcSource object of type p_va_list.
Since
0.0.4
Note
The state of src is copied as well, dst is initialized as if p_va_start(dst) would have been called. There must be a corresponding call to p_va_end(dst) afterwards.

◆ p_va_end

#define p_va_end (   ap)    va_end(ap)

Ends the navigation.

Parameters
apDeclared object of type p_va_list.
Since
0.0.4
Note
There must be a corresponding call to p_va_start(ap) before.

◆ p_va_list

#define p_va_list   va_list

Opaque type holding variable number of arguments navigation.

Since
0.0.4

◆ p_va_start

#define p_va_start (   ap,
  last 
)    va_start(ap, last)

Initializes navigation through a variable number of arguments.

Parameters
apDeclared object of type p_va_list.
lastName of the last argument before ap.
Since
0.0.4
Note
There must be a corresponding call to p_va_end(ap) afterwards.

◆ pboolean_va_arg

#define pboolean_va_arg (   ap)    ((pboolean) p_va_arg(ap, pint))

Unstacks a pboolean variable.

Parameters
app_va_list stack.
Returns
pboolean value.
Since
0.0.4

◆ pchar_va_arg

#define pchar_va_arg (   ap)    ((pchar) p_va_arg(ap, pint))

Unstacks a pchar variable.

Parameters
app_va_list stack.
Returns
pchar value.
Since
0.0.4

◆ pconstpointer_va_arg

#define pconstpointer_va_arg (   ap)    (p_va_arg(ap, pconstpointer))

Unstacks a pconstpointer variable.

Parameters
app_va_list stack.
Returns
pconstpointer value.
Since
0.0.4

◆ pdouble_va_arg

#define pdouble_va_arg (   ap)    (p_va_arg(ap, pdouble))

Unstacks a pdouble variable.

Parameters
app_va_list stack.
Returns
pdouble value.
Since
0.0.4

◆ pfloat_va_arg

#define pfloat_va_arg (   ap)    ((pfloat) p_va_arg(ap, pdouble))

Unstacks a pfloat variable.

Parameters
app_va_list stack.
Returns
pfloat value.
Since
0.0.4

◆ pint16_va_arg

#define pint16_va_arg (   ap)    ((pint16) p_va_arg(ap, pint))

Unstacks a pint16 variable.

Parameters
app_va_list stack.
Returns
pint16 value.
Since
0.0.4

◆ pint32_va_arg

#define pint32_va_arg (   ap)    ((pint32) p_va_arg(ap, pint))

Unstacks a pint32 variable.

Parameters
app_va_list stack.
Returns
pint32 value.
Since
0.0.4

◆ pint64_va_arg

#define pint64_va_arg (   ap)    (p_va_arg(ap, pint64))

Unstacks a pint64 variable.

Parameters
app_va_list stack.
Returns
pint64 value.
Since
0.0.4

◆ pint8_va_arg

#define pint8_va_arg (   ap)    ((pint8) p_va_arg(ap, pint))

Unstacks a pint8 variable.

Parameters
app_va_list stack.
Returns
pint8 value.
Since
0.0.4

◆ pint_va_arg

#define pint_va_arg (   ap)    (p_va_arg(ap, pint))

Unstacks a pint variable.

Parameters
app_va_list stack.
Returns
pint value.
Since
0.0.4

◆ plong_va_arg

#define plong_va_arg (   ap)    (p_va_arg(ap, plong))

Unstacks a plong variable.

Parameters
app_va_list stack.
Returns
plong value.
Since
0.0.4

◆ ppointer_va_arg

#define ppointer_va_arg (   ap)    (p_va_arg(ap, ppointer))

Unstacks a ppointer variable.

Parameters
app_va_list stack.
Returns
ppointer value.
Since
0.0.4

◆ pshort_va_arg

#define pshort_va_arg (   ap)    ((pshort) p_va_arg(ap, pint))

Unstacks a pshort variable.

Parameters
app_va_list stack.
Returns
pshort value.
Since
0.0.4

◆ puchar_va_arg

#define puchar_va_arg (   ap)    ((puchar) p_va_arg(ap, puint))

Unstacks a puchar variable.

Parameters
app_va_list stack.
Returns
puchar value.
Since
0.0.4

◆ puint16_va_arg

#define puint16_va_arg (   ap)    ((puint16) p_va_arg(ap, puint))

Unstacks a puint16 variable.

Parameters
app_va_list stack.
Returns
puint16 value.
Since
0.0.4

◆ puint32_va_arg

#define puint32_va_arg (   ap)    ((puint32) p_va_arg(ap, puint))

Unstacks a puint32 variable.

Parameters
app_va_list stack.
Returns
puint32 value.
Since
0.0.4

◆ puint64_va_arg

#define puint64_va_arg (   ap)    (p_va_arg(ap, puint64))

Unstacks a puint64 variable.

Parameters
app_va_list stack.
Returns
puint64 value.
Since
0.0.4

◆ puint8_va_arg

#define puint8_va_arg (   ap)    ((puint8) p_va_arg(ap, puint))

Unstacks a puint8 variable.

Parameters
app_va_list stack.
Returns
puint8 value.
Since
0.0.4

◆ puint_va_arg

#define puint_va_arg (   ap)    (p_va_arg(ap, puint))

Unstacks a puint variable.

Parameters
app_va_list stack.
Returns
puint value.
Since
0.0.4

◆ pulong_va_arg

#define pulong_va_arg (   ap)    (p_va_arg(ap, pulong))

Unstacks a pulong variable.

Parameters
app_va_list stack.
Returns
pulong value.
Since
0.0.4

◆ pushort_va_arg

#define pushort_va_arg (   ap)    ((pushort) p_va_arg(ap, puint))

Unstacks a pushort variable.

Parameters
app_va_list stack.
Returns
pushort value.
Since
0.0.4