This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: signed vs unsigned comparison warnings
- To: Marc Espie <espie at quatramaran dot ens dot fr>
- Subject: Re: signed vs unsigned comparison warnings
- From: Joern Rennecke <amylaar at cygnus dot co dot uk>
- Date: Tue, 20 Jun 2000 21:24:19 +0100 (BST)
- CC: Joern Rennecke <amylaar at pasanda dot cygnus dot co dot uk>, gcc at gcc dot gnu dot org
> 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.