Rule 3-2-1 and compatible types - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.3 Basic concepts (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=132) +---- Thread: Rule 3-2-1 and compatible types (/showthread.php?tid=1547) |
Rule 3-2-1 and compatible types - getMW - 18-09-2020 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) 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 -or can we consider that
Re: Rule 3-2-1 and compatible types - getMW - 04-11-2020 sorry for raising up this post... has anyone any idea of an answer, on MISRA side in particular? many thanks for helping Re: Rule 3-2-1 and compatible types - misra cpp - 29-01-2021 Please note that there is a definition of 'compatible type' in the glossary Given the usual definitions of int32_t and int64_t, they cannot be the same size, so are never compatible. Furthermore, for example, int and long are never compatible types, even on machines where they have the same size. void foo(int x); and void foo(long x); are always distinct overloads, even if int and long happen to be the same size RE: Rule 3-2-1 and compatible types - misra cpp - 22-07-2021 Please note that there is a definition of 'compatible type' in the glossary Given the usual definitions of int32_t and int64_t, they cannot be the same size, so are never compatible. Furthermore, for example, int and long are never compatible types, even on machines where they have the same size. void foo(int x); and void foo(long x); are always distinct overloads, even if int and long happen to be the same size |