Off-topic: Why no compiler warning for this?

Gedare Bloom gedare at rtems.org
Wed Oct 15 22:15:19 UTC 2014


On Wed, Oct 15, 2014 at 5:20 PM, Mr. Andrei Chichak <groups at chichak.ca> wrote:
>
> On 2014-October-15, at 2:14 AM, Peter Dufault <dufault at hda.com> wrote:
>
> #define ETPU_CHANNEL_BIT(CHAN) (1 << ((CHAN) % 64))
>
> extern void foo(int chan);
> extern void bar(uint32_t bit);
>
> void foo(int chan) {
>    uint32_t bit = ETPU_CHANNEL_BIT(chan);
>    bar(bit);
> }
>
>
>
> I ran this bit through Gimpel lint and the only thing that it picked up is
> that “1” is signed and you are shifting it, should be “1U”. Trivial, but
> that’s what lint is good at.
>
1UL would be better, but yes, shifting through the sign bit is
undefined behavior. Shifting past the end of an unsigned integer
however is well-defined just like unsigned overflow.

> It will usually pick up stuff like the potential of shifting stuff left by
> 64 bits, hmmmmm.
>
> A
>
>
>
> ---------------------
> Andrei Chichak
>
> Systems Developer
> CBF Systems Inc.
> 4-038 NINT INNOVATION CENTRE
> 11421 SASKATCHEWAN DRIVE
> EDMONTON, ALBERTA
> T6G 2M9
> CANADA
>
> Phone: 780-628-2072
> Skype: andrei.chichak
>
>
>
>
>
>
>
>
>
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users



More information about the users mailing list