[previous] 1337 [next] Function defined with a variable number of parameters.
Functions

Functions with variable number of parameters are problematic because the number and types of parameters are not known to the compiler, so no type checking can be performed on the ellipsis arguments. Moreover, default argument promotion will be performed on these arguments, which may generate unexpected results, e.g. when a composite expression is passed.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 1337 --*/

void foo (int a, ...)
{
  /* ... */
}

void f1337 (short b, unsigned char c)
{
  foo (0, b);        // 2nd argument is converted to int
  
  foo (0, c);        // 2nd argument is converted to int
  
  foo (0, c << 4);   // 2nd argument may be greater than 256
}

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents