- Is a function hat can accept a variable number of argument. Theses functions are declared with an ellipsis (’…’) in their argument list, indicating that the function can accept a variable number of argument of different types, the <stdarg.h> header provides facilities for working with variadic functions
Macros :
- is a way to define a piece of code that you can use over and over again its like creating a shortcut.
Va_list :
typedef struct {
unsigned int gp_offset;
unsigned int fp_offset;
void *overflow_arg_area;
void *reg_save_area;
} va_list[1];
- this is a type to hold the information needed by va_start, va_arg, va_end, you can think of it as a container for the variable argument, this type is basically a struct and its members are :
- gp_offset : ‘gp_offset’ field serves as a reference point to locate the starting position of the general purpose register save area within the entire argument list. By knowing this offset, the function can correctly access and retrieve the value stored in the general purpose registers that were passed as arguments.
- general-purpose-register-area : is a designated memory region where the values of the general purpose registers are stored during the execution of a function, General-purpose register are special-purpose storage location within the CPU that a program can use to store temporary data. in our machine there’s 6 registers and each one can hold an argument of 8bytes.
- fp_offset : same as gp_offset is it measures the distance from the beginning of argument list to the floating point register save area.
- floating point register save area: a register that is dedicated memory region that serves as a temporary storage space for preserving the value of floating point registers during the execution of a funct. in our machine there’s 8 regsiters and each one can hold a floating argument of 16bytes.
- overflow_arg_area : this field is a pointer to the area where overflow arguments are stored in stack. overflow arguments are used when the number of arguments exceeds the numbers of registers available for parameters pasing.
- reg_save_area : this field is a pointer to the area where the contents of registers are saved.