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: 1 << BITS_PER_UNIT


> Did you run:
> 
> #include <stdio.h>
> #define BITS_PER_UNIT 8
> main() {
>   printf("%x %x\n",
>	 (1 << BITS_PER_UNIT) - 1,
>	 (2 << (BITS_PER_UNIT - 1)));
> }


I wasn't suggesting ((1 << x) - 1) == (2 << (x - 1)), that is obviously 
false, but (1 << x) == (2 << (x - 1)).  Do some elementary math.

The point is that (1 << BITS_PER_UNIT) - 1 gets you a warning, but
(2 << (BITS_PER_UNIT - 1)) - 1 gives the same result but no warning, and 
is well within the spec since (BITS_PER_UNIT - 1) is less than the word 
size.

Richard.




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