Re: sizeof(unsigned long long)
Re: sizeof(unsigned long long)
- Subject: Re: sizeof(unsigned long long)
- From: "Clark Cox" <email@hidden>
- Date: Sat, 27 Sep 2008 16:12:27 -0700
On Sat, Sep 27, 2008 at 2:49 PM, Daniel Luis dos Santos
<email@hidden> wrote:
> Hello,
>
> I have a piece of C code that generates an unsigned long long from an
> sequence of unsigned char's.
>
> When I do sizeof(unsigned long long) i get 8.
> Afterwards I try to shift each unsigned char into its position along the
> destination unsigned long long variable, but I get a warning from the
> compiler that I am shifting beyond the type's capacity. That is not
> surprising since I am targeting 32 bit.
This has nothing to do with 32-bit vs. 64-bit. In C, when you shift an
unsigned char, the result is an int (or unsinged int on some
platforms). GCC is warning you that you are shifting beyond the
capacity of an int. To avoid this, cast your unsigned char's to
unsigned long longs *before* you shift.
> Then I don't understand why the size of returns 8. Shouldn't it return 4 ?
unsigned long long is *always* at least 64-bits. This is guaranteed by
the C standard.
--
Clark S. Cox III
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden