18-09-2020, 08:47 AM
the rule says "All declarations of an object or function shall have compatible types."
the question is: how do you define "compatible types"?
-if we think it is similar to MISRA-C:2004 8.4 "If objects or functions are declared more than once their types shall be compatible."
or to MISRA-C:2012 8.3 that says "Compatible versions of the same basic type may be used interchangeably. For example, int, signed and signed int are all equivalent."
=> then we can look at the definition of compatible types defined in C norm (sections 6.1.2.6, 6.5.2, 6.5.3 and 6.5.4 for C90)
-but C++ norm does not define those compatible types and even more, it says in the Annex C.1 3.9(5)
do you use another definition?
Practical example: on the example given in MISRA-C++ documentation
-do you expect that it is always non compliant, whatever the platform is? (whatever are the size of int32_t and int64_t)
-or can we consider that
the question is: how do you define "compatible types"?
-if we think it is similar to MISRA-C:2004 8.4 "If objects or functions are declared more than once their types shall be compatible."
or to MISRA-C:2012 8.3 that says "Compatible versions of the same basic type may be used interchangeably. For example, int, signed and signed int are all equivalent."
=> then we can look at the definition of compatible types defined in C norm (sections 6.1.2.6, 6.5.2, 6.5.3 and 6.5.4 for C90)
-but C++ norm does not define those compatible types and even more, it says in the Annex C.1 3.9(5)
Quote:Change: C allows “compatible types” in several places, C++ does notso what are compatible types in C++? do you use C compatible types even if C++ norm rejects them?
do you use another definition?
Practical example: on the example given in MISRA-C++ documentation
Code:
// File a.cpp
extern int32_t a;
// File b.cpp
extern int64_t a; // Non-compliant – not compatible
-or can we consider that
- it can be compliant on platform where int32_t and int64_t have same signess and size
- it can be non-compliant on platforms where size are different