I\'m using IAR Workbench compiler with MISRA C:2004 checking on.
The fragment is:
#define UNS_32 unsigned int
UNS_32 arg = 3U;
UNS_32 converted_arg = (
In the earliest days of MISRA, programs to which it was applied would sometimes be targeted toward compilers whose behavior would not comply with the not-yet-published C89 Standard. On the machines for which C was invented, operations on 16-bit values cost the same as operations on 8-bit values. Promoting char
values to int
, and truncating the results when storing back to char
was actually cheaper and easier than performing arithmetic on char
values directly. While the C Standard, once published, would mandate that all C implementations must promote all integer values to an int
type that can accommodate at least the range -32767..32767, or an unsigned
type that can accommodate at least 0..65535, or else some larger type, 1980s compilers that targeted 8-bit machines didn't always do that.
Although it may seem crazy nowadays to try to use a C compiler that can't meet those requirements, programmers in the 1980s would have often faced the choice between using a "C-ish" compiler or writing everything in assembly language. Some of the rules in MISRA, including the "inherent type" rules, were designed to ensure that programs would work even if run on weird implementations which treat int
as an 8-bit type.