<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.12.3">
</HEAD>
<BODY>
On Wed, 2007-05-23 at 18:45 -0500, Michael Hennebry wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">On Wed, 23 May 2007, Mike McCarty wrote:</FONT>

<FONT COLOR="#000000">> Michael Hennebry wrote:</FONT>
<FONT COLOR="#000000">> > On Wed, 23 May 2007, George Arseneault wrote:</FONT>
<FONT COLOR="#000000">> ></FONT>
<FONT COLOR="#000000">> ></FONT>
<FONT COLOR="#000000">> >>Now the bad news... C, C++, gnu, several variations on</FONT>
<FONT COLOR="#000000">> >>the ISO; not to mention all the libraries, etc.  And,</FONT>
<FONT COLOR="#000000">> >>to top it off, some of the stuff in the book just</FONT>
<FONT COLOR="#000000">> >>doesn't work.  (A program to demonstrate the various</FONT>
<FONT COLOR="#000000">> >>types of integer variables and how to display them</FONT>
<FONT COLOR="#000000">> >>with printf(), failed to show any difference with any</FONT>
<FONT COLOR="#000000">> >>arguments I could find.)</FONT>
<FONT COLOR="#000000">> ></FONT>
<FONT COLOR="#000000">> ></FONT>
<FONT COLOR="#000000">> > Should they have produced different results?</FONT>
<FONT COLOR="#000000">></FONT>
<FONT COLOR="#000000">> On big-endian machines, they can. For example, with two's complement</FONT>
<FONT COLOR="#000000">> arithmetic on a big-endian machine,</FONT>
<FONT COLOR="#000000">></FONT>
<FONT COLOR="#000000">> printf("%d\n",-2);</FONT>
<FONT COLOR="#000000">></FONT>
<FONT COLOR="#000000">> does not result in</FONT>
<FONT COLOR="#000000">></FONT>
<FONT COLOR="#000000">> -2</FONT>

<FONT COLOR="#000000">It should.</FONT>
<FONT COLOR="#000000">printf, declared or not, will look for an int and get it.</FONT>

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


<FONT COLOR="#000000">> > Printing (int)sizeof(typename) will distinguish some types.</FONT>
<FONT COLOR="#000000">> > Note that short, int and long usually only have two distinct sizes.</FONT>
<FONT COLOR="#000000">> > It's allowed, but rare, for all the arithmetic types to have size 1.</FONT>
<FONT COLOR="#000000">></FONT>
<FONT COLOR="#000000">> Note that what you suggest works because sizeof(.) for integer</FONT>
<FONT COLOR="#000000">> types is going to be a small number. The only portable means</FONT>

<FONT COLOR="#000000">For small read <=16.</FONT>

<FONT COLOR="#000000">> of displaying an unsigned integer of unknown size is</FONT>
<FONT COLOR="#000000">></FONT>
<FONT COLOR="#000000">> printf("Thing = %ul\n",(unsigned long int)Thing);</FONT>
<FONT COLOR="#000000">></FONT>
<FONT COLOR="#000000">> For "rare" read "no known implementation". Since long int</FONT>
<FONT COLOR="#000000">> is required to be at least 32 bits, that would require</FONT>
<FONT COLOR="#000000">> that char be at least 32 bits.</FONT>

<FONT COLOR="#000000">And double has to be more.</FONT>

<FONT COLOR="#000000">My recollection is that there was a</FONT>
<FONT COLOR="#000000">Cray compiler that had 64-bit chars.</FONT>
<FONT COLOR="#000000">Anyone know for sure?</FONT>

<FONT COLOR="#000000">-- </FONT>
<FONT COLOR="#000000">Mike   <A HREF="mailto:hennebry@web.cs.ndsu.NoDak.edu">hennebry@web.cs.ndsu.NoDak.edu</A></FONT>
<FONT COLOR="#000000">"Horse guts never lie."  -- Cherek Bear-Shoulders</FONT>

</PRE>
</BLOCKQUOTE>
sizeof generally returns size in bytes or words (depending on how the implementer read the spec) I have never seen it return words.<BR>
<BR>
    And the Cray stored 8 characters in 64 bits using ASCII coding a LONG time ago.  I had forgotten about that.  I think that was the model where you sat on the processing unit when you were at the console.<BR>
<BR>
Regards,<BR>
Les H 
</BODY>
</HTML>