MISRA C:2023 Rule 21.23
All operand arguments to any multi-argument type-generic macros declared in <tgmath.h> shall have the same standard type
Since R2024a
Description
Rule Definition
All operand arguments to any multi-argument type-generic macros declared in <tgmath.h> shall have the same standard type.
Rationale
If you use the same standard type for all arguments to a type-generic macro, it becomes clear what type is used for evaluation of the macro expression.
For instance, if you use float
variables for both arguments to the pow()
macro, it is clear that evaluation of the macro expression adheres to the precision requirements of the float
type. However, if one argument is float
and the other double
, it is unclear which type is used for the evaluation.
On platforms with extended real types, floating-point data types might not be ordered strictly by precision, so the type used for evaluation of the macro expression might actually lead to a loss of precision.
Polyspace Implementation
The rule checker reports violations if all arguments to a type-generic macro declared in tgmath.h
do not have the same standard type (after integer promotion is applied to integer types). For example, the rule checker reports a violation:
If one argument has an integer type and another argument has a floating-point type.
If one argument has an integer type and another argument has a different integer type (after integer promotion is applied). For example, one argument might have type
char
,short
orint
, while another might have typelong
.If one argument has an essentially real floating-point type and another argument has an essentially complex floating-point type. For more information on essential types, see
MISRA C:2012 Rule 10.1
.If one argument has a floating-point type and another argument has a floating-point type of different size.
For some functions such as frexp
, the final argument is meant for outputs. The rule checker skips this output argument when checking for rule violations.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group:Standard Libraries |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2024a