Re: amd64: why is sizeof(int) =4? why not =8?
On Wed, Apr 05, 2006 at 04:42:37PM -0500, Mike McCarty wrote:
> Mitchell Laks wrote:
> >On Wednesday 05 April 2006 15:16, Mike McCarty wrote:
> >
> >
> >>This program has defects. The type of the results of
> >>the sizeof operator is an unsigned integer of unspecified
> >>size. The only portable way to do this is...
> >>
> >> printf("Size of int is %lu\n",(unsigned long)sizeof(int));
> >>
> >
> >
> >Why do I have cast something from size_t? I see the construct I used in
> >"C a reference Manual" by Harbisson and Steele p148.
>
> Well, it is defective. The C Standard simply states that the
> type returned by the sizeof operator is an unsigned integer
> type, but which one is implementation dependent. Since you
> don't know whether it be an unsigned short int, or an
> unsigned long int, you have to cast, because they have
If it turns our to have been unsigned long long, have you possibly just
truncated it? (Not that I really expect sizeof(int) to be greater than,
say, 128 for the foreseeable future.)
> (potentially) different formats, and definitely different
> format specifiers. In any case, the use of "%d" which
> specifies a signed integer conversion is just wrong,
> since sizeof returns an unsigned integer type.
>
>
> >I am not a c expert - and I dont understand why you do the cast.
>
> Everybody is ignorant, just about different things.[*]
> Well, I just gave you the explanation.
>
> >Do you have an example of a compiler where the length of sizeof(int) is
> >greater than size_t ?
>
> Umm, it's likely to be the other way around. In any case, using
> a signed integer conversion format specifier with an unsigned
> integer type is wrong.
>
> [snip]
>
> * Will Rogers
>
> Mike
> --
> p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
> This message made from 100% recycled bits.
> You have found the bank of Larn.
> I can explain it for you, but I can't understand it for you.
> I speak only for myself, and I am unanimous in that!
>
>
> --
> To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact
> listmaster@lists.debian.org
>
Reply to: