Re: shame on MISRA



On Apr 22, 12:44 pm, Marcin Wolcendorf <wolce...@xxxxxxxxxxxxxx>
wrote:

No. It doesn't. One of the rules states (I don't have them in front of me),
that you can't use signed constants (like -1U) to set unsigned variables. -1U
is a nice value of all 1s binary, convenient for masking. Well, you can get
rid of complaints in two ways:
- write 0xFFFFFFFFU instead of -1U (how many Fs do you see? 8? 7? 9? If someone
removes one F will you be able to spot it easily? IMHO- no, you will not.
Even, if you have it #defined),
- add a signed variable, initialise it with -1U, and convert it explicitly to
unsigned in expression (superfluous variable does not add to visibility).
Now, both ways are clumsy, hard to read and look like a dirty hack IMHO.
What would you say?

Just use ~0U

.



Relevant Pages

  • Re: shame on MISRA
    ... Marcin Wolcendorf wrote: ... that you can't use signed constants to ... set unsigned variables. ... If you need all 1s, then using 0xffff is, IMO, bad practice ...
    (comp.arch.embedded)
  • Re: shame on MISRA
    ... that you can't use signed constants to set unsigned variables. ... is a nice value of all 1s binary, convenient for masking. ... I can't recall the reason, ...
    (comp.arch.embedded)
  • Re: shame on MISRA
    ... that you can't use signed constants to set unsigned variables. ... is a nice value of all 1s binary, convenient for masking. ... I sometimes use 0xFFFFffff which is with a constant width font quite ...
    (comp.arch.embedded)