Off-topic: Why no compiler warning for this?

Peter Dufault dufault at
Wed Oct 15 08:14:31 UTC 2014

This is really a gcc question, but with Joel working to wipe out warnings and not wanting to start a thread on another list I'm asking here.  I stumbled on this sequence (obviously simplified) in my code.  The "XXX" indicates a restriction I intended to remove but didn't, and it would have broken new code I've been writing.  I noticed it before hitting the issue.

The ETPU_CHANNEL_BIT macro is appropriate for the MPC5554 eTPUA with channels 0 through 31.  The macro is going to left-shift out of the unit32_t for the channels 32 through 63 in eTPUB (not sure why I bothered with the modulus, it's going to be totally broken for larger channel numbers).  Code:

#include <inttypes.h>

/* XXX Need a way to specify which eTPU the channel is in.
 *     They happen to both be in A.
#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);

Here is the optimization level and the compiler warnings I had in effect.  I even added -Wstrict-overflow=5 and -O4 hoping to get a warning without luck.


Anyone else surprised?  Am I missing something obvious?  Any suggested additional warnings?

Peter Dufault
HD Associates, Inc.      Software and System Engineering

More information about the users mailing list