plibsys 0.0.5
pstdarg.h File Reference

Variable arguments. More...

#include <pmacros.h>
#include <ptypes.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>

Go to the source code of this file.

Macros

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

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.:

  • Integer arguments of types lower than pint are always promoted to pint, or puint if pint is not enough.
  • Arguments of type float are always promoted to double.
  • Arrays are always promoted to pointers.

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.

Definition in file pstdarg.h.

Macro Definition Documentation

◆ p_va_arg

#define p_va_arg ( ap,
type )
Value:
(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

Definition at line 104 of file pstdarg.h.

◆ p_va_copy

#define p_va_copy ( dst,
src )
Value:
((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.

Definition at line 126 of file pstdarg.h.

◆ p_va_end

#define p_va_end ( ap)
Value:
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.

Definition at line 112 of file pstdarg.h.

◆ p_va_list

#define p_va_list   va_list

Opaque type holding variable number of arguments navigation.

Since
0.0.4

Definition at line 84 of file pstdarg.h.

◆ p_va_start

#define p_va_start ( ap,
last )
Value:
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.

Definition at line 93 of file pstdarg.h.

◆ pboolean_va_arg

#define pboolean_va_arg ( ap)
Value:
#define p_va_arg(ap, type)
Gets the next argument in the list.
Definition pstdarg.h:104
int pint
Type for an int.
Definition ptypes.h:120
signed int pboolean
Type for a bool.
Definition ptypes.h:114

Unstacks a pboolean variable.

Parameters
app_va_list stack.
Returns
pboolean value.
Since
0.0.4

Definition at line 226 of file pstdarg.h.

◆ pchar_va_arg

#define pchar_va_arg ( ap)
Value:
char pchar
Type for a char.
Definition ptypes.h:116

Unstacks a pchar variable.

Parameters
app_va_list stack.
Returns
pchar value.
Since
0.0.4

Definition at line 235 of file pstdarg.h.

◆ pconstpointer_va_arg

#define pconstpointer_va_arg ( ap)
Value:
const void * pconstpointer
Type for a const pointer.
Definition ptypes.h:111

Unstacks a pconstpointer variable.

Parameters
app_va_list stack.
Returns
pconstpointer value.
Since
0.0.4

Definition at line 217 of file pstdarg.h.

◆ pdouble_va_arg

#define pdouble_va_arg ( ap)
Value:
double pdouble
Type for a double precision float.
Definition ptypes.h:136

Unstacks a pdouble variable.

Parameters
app_va_list stack.
Returns
pdouble value.
Since
0.0.4

Definition at line 316 of file pstdarg.h.

◆ pfloat_va_arg

#define pfloat_va_arg ( ap)
Value:
float pfloat
Type for a float.
Definition ptypes.h:134

Unstacks a pfloat variable.

Parameters
app_va_list stack.
Returns
pfloat value.
Since
0.0.4

Definition at line 307 of file pstdarg.h.

◆ pint16_va_arg

#define pint16_va_arg ( ap)
Value:
signed short pint16
Type for signed 16 bit.
Definition ptypes.h:77

Unstacks a pint16 variable.

Parameters
app_va_list stack.
Returns
pint16 value.
Since
0.0.4

Definition at line 154 of file pstdarg.h.

◆ pint32_va_arg

#define pint32_va_arg ( ap)
Value:
signed int pint32
Type for signed 32 bit.
Definition ptypes.h:81

Unstacks a pint32 variable.

Parameters
app_va_list stack.
Returns
pint32 value.
Since
0.0.4

Definition at line 172 of file pstdarg.h.

◆ pint64_va_arg

#define pint64_va_arg ( ap)
Value:
signed __int64 pint64
Type for signed 64 bit.
Definition ptypes.h:96

Unstacks a pint64 variable.

Parameters
app_va_list stack.
Returns
pint64 value.
Since
0.0.4

Definition at line 190 of file pstdarg.h.

◆ pint8_va_arg

#define pint8_va_arg ( ap)
Value:
signed char pint8
Type for signed 8 bit.
Definition ptypes.h:73

Unstacks a pint8 variable.

Parameters
app_va_list stack.
Returns
pint8 value.
Since
0.0.4

Definition at line 136 of file pstdarg.h.

◆ pint_va_arg

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

Unstacks a pint variable.

Parameters
app_va_list stack.
Returns
pint value.
Since
0.0.4

Definition at line 253 of file pstdarg.h.

◆ plong_va_arg

#define plong_va_arg ( ap)
Value:
long plong
Type for a long.
Definition ptypes.h:122

Unstacks a plong variable.

Parameters
app_va_list stack.
Returns
plong value.
Since
0.0.4

Definition at line 262 of file pstdarg.h.

◆ ppointer_va_arg

#define ppointer_va_arg ( ap)
Value:
void * ppointer
Type for a pointer.
Definition ptypes.h:109

Unstacks a ppointer variable.

Parameters
app_va_list stack.
Returns
ppointer value.
Since
0.0.4

Definition at line 208 of file pstdarg.h.

◆ pshort_va_arg

#define pshort_va_arg ( ap)
Value:
short pshort
Type for a short.
Definition ptypes.h:118

Unstacks a pshort variable.

Parameters
app_va_list stack.
Returns
pshort value.
Since
0.0.4

Definition at line 244 of file pstdarg.h.

◆ puchar_va_arg

#define puchar_va_arg ( ap)
Value:
unsigned int puint
Type for an unsigned int.
Definition ptypes.h:129
unsigned char puchar
Type for an unsigned char.
Definition ptypes.h:125

Unstacks a puchar variable.

Parameters
app_va_list stack.
Returns
puchar value.
Since
0.0.4

Definition at line 271 of file pstdarg.h.

◆ puint16_va_arg

#define puint16_va_arg ( ap)
Value:
unsigned short puint16
Type for unsigned 16 bit.
Definition ptypes.h:79

Unstacks a puint16 variable.

Parameters
app_va_list stack.
Returns
puint16 value.
Since
0.0.4

Definition at line 163 of file pstdarg.h.

◆ puint32_va_arg

#define puint32_va_arg ( ap)
Value:
unsigned int puint32
Type for unsigned 32 bit.
Definition ptypes.h:83

Unstacks a puint32 variable.

Parameters
app_va_list stack.
Returns
puint32 value.
Since
0.0.4

Definition at line 181 of file pstdarg.h.

◆ puint64_va_arg

#define puint64_va_arg ( ap)
Value:
unsigned __int64 puint64
Type for unsigned 64 bit.
Definition ptypes.h:97

Unstacks a puint64 variable.

Parameters
app_va_list stack.
Returns
puint64 value.
Since
0.0.4

Definition at line 199 of file pstdarg.h.

◆ puint8_va_arg

#define puint8_va_arg ( ap)
Value:
unsigned char puint8
Type for unsigned 8 bit.
Definition ptypes.h:75

Unstacks a puint8 variable.

Parameters
app_va_list stack.
Returns
puint8 value.
Since
0.0.4

Definition at line 145 of file pstdarg.h.

◆ puint_va_arg

#define puint_va_arg ( ap)
Value:

Unstacks a puint variable.

Parameters
app_va_list stack.
Returns
puint value.
Since
0.0.4

Definition at line 289 of file pstdarg.h.

◆ pulong_va_arg

#define pulong_va_arg ( ap)
Value:
unsigned long pulong
Type for an unsigned long.
Definition ptypes.h:131

Unstacks a pulong variable.

Parameters
app_va_list stack.
Returns
pulong value.
Since
0.0.4

Definition at line 298 of file pstdarg.h.

◆ pushort_va_arg

#define pushort_va_arg ( ap)
Value:
unsigned short pushort
Type for an unsigned short.
Definition ptypes.h:127

Unstacks a pushort variable.

Parameters
app_va_list stack.
Returns
pushort value.
Since
0.0.4

Definition at line 280 of file pstdarg.h.