Versions Compared

Key

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

Variadic functions can accept a variable number of arguments, but they are problematic. Variadic functions define an implicit contract between the function writer and the function user that allows the function to determine the number of arguments passed in any particular invocation. Failure to exercise care when invoking a variadic function to ensure that it knows when to stop processing arguments may result in undefined behavior.

...

Non-Compliant Code Example

If In this non-compliant example, the function above is called as follows:

...

Code Block
bgColor#ccccff
int avg = average(1, 4, 6, 4, 1, -1);

Non-Compliant Code Example Example

Another common mistake is to use more format specifiers than supplied arguments. This results in undefined behavior, which could end up pulling extra values off the stack and unintentionally exposing data. The following example illustrates a case of this:

...

Wiki Markup
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] Section 7.15, "Variable arguments,"; and Section 7.19.6.8, "The {{vfprintf}} function"
\[[Seacord 05c|AA. C References#Seacord 05c]\]

...