This is the mail archive of the gcc-help@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: bug?


On Jun 19, 2001, Ingo Krabbe <ikrabbe@earthling.net> wrote:

> On 19 Jun 2001, Alexandre Oliva wrote:
>> > That's a kind of why I used ~(~(x^x)<<(sizeof(x)*8-n)).

>> Make the `8' `CHAR_BIT'.  BTW, did you consider what happens if x is
>> narrower than size_t (the type of sizeof(x)) for both signed and
>> unsigned integer types?

> Hmm, I considered that sizeof(x) returns the size of bytes which has a
> length of 8 though a char may be longer ?!

sizeof(char) is always 1, but there's no guarantee that 1 byte will
contain exactly 8 bits.  That's where CHAR_BIT comes into play.

> Then I considered that ~(x^x) gives a stream of '1' as long as x.

Right.  But then, the shift operation causes the result to be promoted
to a type at least as wide as size_t.  This may cause sign extension,
if x is a signed type, or zero extension, if x is unsigned.  So, you
may get different bit patterns depending on the signedness of x.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me


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