MISRA Discussion Forums
Essential rank of variabls and constants - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.10 The essential type model (https://forum.misra.org.uk/forumdisplay.php?fid=165)
+---- Thread: Essential rank of variabls and constants (/showthread.php?tid=1129)



Essential rank of variabls and constants - sca2012 - 20-11-2014

According p.8.10.2 and Appendix D, there are 5 ranks for signed and unsigned types for variables, defined, presumably, by their standard types. In particular, standard types int, long and long long are considered to have all different ranks.

According to p. D.3, for a constant, rank of its essential type is determined by its value. Now assume there is a (signed) constant that requires, say, 32 bits to represent the value. Is its rank the same as that of a signed int or signed long variable? And, correspondingly, for a 64-bit constant, will its rank be the same as that of signed long or signed long long variable?

Thank you.


Re: Essential rank of variabls and constants - misra-c - 05-12-2014

The following examples assumes the following type ranges:
  • char - 8 bits
    short - 16 bits
    int - 32 bits
    long - 64 bits
and that the constants are written in decimal form with no suffices.

Code:
| Constant value range                     | Essential Type
| -2**7 .. 2**7-1                          | essentially signed char  |
| -2**15 .. -2**7-1  and  2**7 .. 2**15-1  | essentially signed short |
| -2**31 .. -2**15-1 and 2**15 .. 2**31-1  | essentially signed int   |
| -2**63 .. -2**31-1 and 2**31 .. 2**63-1  | essentially signed long  |
So for example 2147483647 (2**31-1) will have an essential type of essentially signed int, but 2147483648 (2**31) will have an essential type of essentially signed long.

2**X is used to represent 2 to the power X