This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: signed vs unsigned comparison warnings


> If you are sure the value is positive, you can use shifts instead of
> division, or am I missing something ?
> 
> You don't have to declare the variable unsigned and suffer from all the
> nasty trouble this entails.

But right shifts of a signed value give an implementation-defined result...
now that's something we should warn about...

Besides, the powers of two often apper as the size of some type.  You'd
have to work a lot of autoconf magic to convert that into a shift count.
It's cleaner to do an unsigned divide.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]