OT: Requesting C advice
Mike McCarty
Mike.McCarty at sbcglobal.net
Wed May 23 21:26:27 UTC 2007
Michael Hennebry wrote:
> On Wed, 23 May 2007, George Arseneault wrote:
>
>
>>Now the bad news... C, C++, gnu, several variations on
>>the ISO; not to mention all the libraries, etc. And,
>>to top it off, some of the stuff in the book just
>>doesn't work. (A program to demonstrate the various
>>types of integer variables and how to display them
>>with printf(), failed to show any difference with any
>>arguments I could find.)
>
>
> Should they have produced different results?
On big-endian machines, they can. For example, with two's complement
arithmetic on a big-endian machine,
printf("%d\n",-2);
does not result in
-2
but likely in
-65535
or
-2147483647
> Printing (int)sizeof(typename) will distinguish some types.
> Note that short, int and long usually only have two distinct sizes.
> It's allowed, but rare, for all the arithmetic types to have size 1.
Note that what you suggest works because sizeof(.) for integer
types is going to be a small number. The only portable means
of displaying an unsigned integer of unknown size is
printf("Thing = %ul\n",(unsigned long int)Thing);
For "rare" read "no known implementation". Since long int
is required to be at least 32 bits, that would require
that char be at least 32 bits.
Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
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!
More information about the fedora-list
mailing list