http://www.cplusplus.com/reference/cstdarg/va_list/ According to the above link, va_list is an argument or parameter used in some macros - va_start, va_arg, va_end. These macros are present in the stdarg.h file.

I know that va_list can hold multiple values but what kind of an entity is va_list? My question is what is the underlying mechanism behind va_list? How is it able to hold multiple values? (For example, an array can hold multiple values and the mechanism behind it is multiple memory locations referenced by subscript values. Array is a predefined data structure present in C.)

My second question is where is va_list defined?

  • 2
    Unclear what help you need. Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it’s hard to tell what problem you are trying to solve or what aspect of your approach needs to be corrected or explained. See the How to Ask page for help clarifying this question. – gnat Mar 18 '14 at 19:26
  • @RobertHarvey I know that it is used as a parameter for the macros in <cstdarg> but what exactly is this entity. And where is it defined? – aste123 Mar 18 '14 at 19:29
  • @gnat I will edit the question. – aste123 Mar 18 '14 at 19:30
  • 2
    It's defined in stdarg.h There are many places on the Internet where you can view the source; here's one: opensource.apple.com/source/xnu/xnu-792.13.8/EXTERNAL_HEADERS/… – Robert Harvey Mar 18 '14 at 19:42

The answer to your question is here: https://stackoverflow.com/questions/4958384/what-is-the-format-of-the-x86-64-va-list-structure

The va_list type is an array containing a single element of one structure containing the necessary information to implement the va_arg macro. The C definition of va_list type is given in figure below

typedef struct {
   unsigned int gp_offset;
   unsigned int fp_offset;
   void *overflow_arg_area;
   void *reg_save_area;
} va_list[1];

va_list is defined in stdarg.h as http://www.cplusplus.com/reference/cstdarg/va_list/ states.

You can refer to the book "The Standard C Library" by Plauger if you need to know the ins and outs of the std libc.


See also the ABI specification and the calling conventions for your target platform. For x86-64/Linux, read the x86-64 ABI supplement (see also the x86 calling conventions wikipage).

Several aspects of <stdarg.h> are built in the GCC compiler (e.g. thru __builtin_va_start, __builtin_va_arg, etc...) and <stdarg.h> is provided by the compiler. See also its __builtin_va_arg_pack, etc...

You might also be interested by libffi (e.g. if you want to dynamically build a call to a variadic function).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.