...
The C Standard identifies five distinct situations in which undefined behavior (UB)may arise as a result of invoking a function using a declaration that is incompatible with its definition or by supplying incorrect types or numbers of arguments:
UB | Description |
A pointer is used to call a function whose type is not compatible with the referenced type (6.3.2.3). | |
For a call to a function without a function prototype in scope, the number of arguments does not equal the number of parameters (6.5.2.2). | |
For a call to a function without a function prototype in scope where the function is defined with a function prototype, either the prototype ends with an ellipsis or the types of the arguments after promotion are not compatible with the types of the parameters (6.5.2.2). | |
For a call to a function without a function prototype in scope where the function is not defined with a function prototype, the types of the arguments after promotion are not compatible with those of the parameters after promotion (with certain exceptions) (6.5.2.2). | |
A function is defined with a type that is not compatible with the type (of the expression) pointed to by the expression that denotes the called function (6.5.2.2). |
...
The header <tgmath.h>
provides type-generic macros for math functions. Although most functions from the <math.h>
header have a complex counterpart in <complex.h>
, several functions do not. Calling any of the following type-generic functions with complex values results in is undefined behavior.
Functions That Should Not Be Called with Complex Values
...
If the clog2()
function is not available for an implementation as an extension, the programmeng programmer can take the base-2 logarithm of a complex number, using log()
instead of log2()
, because log()
can be used on complex arguments, as shown in this compliant solution:
...
Code Block | ||||
---|---|---|---|---|
| ||||
fd = open(ms, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC); |
Note that, technically, it is also incorrect to pass a third argument to open()
when not creating a new file (that is, with the O_CREAT
flag not set).
...