[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
}


MISRA C:2012 Rules applicable to message 1337:

Rule-17.1  (Required) The features of <stdarg.h> shall not be used


QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents