Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Wiki Markup
The variable parameters of a variadic function, i.e. those that correspond with the position of the ellipsis, are interpreted by the {{va_arg()}} macro.  The {{va_arg()}} macro is used to extract the next argument from an initialized argument list within the body of a variadic function implementation. The size of each parameter is determined by the specified {{type}}. If {{the type}} is inconsistent with the corresponding argument, the behavior is undefined and may result in misinterpreted data or an alignment error \[[EXP36-C. Do not convert between pointers to objects with differing alignments]\].

Because The variable arguments to a variadic functions are untypedfunction are not checked for type by the compiler.  Therefore, the programmer is responsible for ensuring that they are compatible with the same type as the corresponding parameter except for the following casesafter the default argument promotions:

  • integer arguments of types ranked lower than int are promoted to int, if int can hold all the values of that type, otherwise they are promoted to unsigned int (the "integer promotions");
  • arguments of type float are promoted to double
  • one type is a signed integer type, the other type is the corresponding unsigned integer type, and the value is representable in both types;
  • one type is pointer to void and the other is a pointer to a character type.

Non-Compliant Code Example (type interpretation error)

...

Wiki Markup
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] Section 6.5.2.2, "Function calls"; 7.15, "Variable arguments"