![]() |
![]() |
1277 | ![]() |
||||
![]() | |||||||
| Constants | |||||||
This hexadecimal constant does not have a "u" or "U" suffix. Is the constant intended to be of signed type or unsigned type ? Any unsuffixed hex constant which can be represented in type signed int will be of type signed int rather than unsigned int. The type of an integer constant depends on its value and the implemented size of an int (e.g. whether it is a 16 bit or 32 bit quantity ) as well as the presence of suffixes. More ... A hexadecimal constant is rarely used to represent signed data. If it really is intended to be of unsigned type, it is good practice to add a "u" or "U" suffix so that the signedness is explicit. For example:
/*PRQA S 1254,1255,2017,3120,3211,3408,3602 ++*/
/***********************************
* OPTIONS: -s int=16
**********************************/
signed int sia = 0x1234; /* Message 1277 */
signed int sib = 0x7FFF; /* Message 1277 */
signed long sic = 0x10000; /* Message 1277 */
unsigned int uia = 0x1234u; /* */
unsigned int uib = 0x7FFFu; /* */
unsigned int uic = 0x8000; /* Message 1277 + 1281 */
unsigned long ula = 0x80000000; /* Message 1277 + 1281 */
unsigned long ulb = 0x80000000u; /* */
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |