Re: OT: Requesting C advice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux