This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: bug?
- To: Ingo Krabbe <i dot krabbe at dokom dot net>
- Subject: Re: bug?
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 19 Jun 2001 13:02:16 -0300
- Cc: David Berthelot <davidb at Magma-DA dot COM>, Ben Kohlen <bckohlen at yahoo dot com>, <gcc-help at gcc dot gnu dot org>
- Organization: GCC Team, Red Hat
- References: <Pine.LNX.4.33.0106191448210.22643-100000@flathead.burg.de>
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