Re: OT: Requesting C advice

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

 



On Wed, 23 May 2007, Mike McCarty wrote:

> 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

It should.
printf, declared or not, will look for an int and get it.

printf("%u\n", -2);
is more interesting.
We might be in the domain of nasal demons.
printf("%u\n", (unsigned)-2);
Is legal, but rather obviously will not print "-2\n".
It will probably print something even regardless of endianness.


> > 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

For small read <=16.

> 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.

And double has to be more.

My recollection is that there was a
Cray compiler that had 64-bit chars.
Anyone know for sure?

-- 
Mike   hennebry@xxxxxxxxxxxxxxxxxxxxx
"Horse guts never lie."  -- Cherek Bear-Shoulders


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

  Powered by Linux