Criticism of the C programming language: Difference between revisions

Content deleted Content added
m more neutral
Line 21:
 
===Variadic functions===
Another source of bugs is [[variadic function]]s, which take a variable number of arguments. Unlike other prototyped C functions, checking the types of arguments to variadic functions at compile-time is, in general, impossible without additional information. If the wrong type of data is passed, the effect is unpredictable, and often fatal. Variadic functions also handle null pointer constants in a way which is often surprising to those unfamiliar with the language semantics. For example, NULL must be cast to the desired pointer type when passed to a variadic function. The [[printf]] family of functions supplied by the standard library, used to generate formatted text output, has been noted for its error-prone variadic interface, which relies on a format string to specify the number and typetypes of trailing arguments.
 
However, type-checking of variadic functions from the standard library is a quality-of-implementation issue; many modern compilers do type-check <code>printf</code> calls, producing warnings if the argument list is inconsistent with the format string. Even so, not all <code>printf</code> calls can be checked statically since the format string can be built at runtime, and other variadic functions typically remain unchecked.