delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/24/06:41:41

Date: Mon, 24 Jan 2000 09:29:15 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: David Cleaver <davidis AT ou DOT edu>
cc: djgpp AT delorie DOT com
Subject: Re: Weird output of printf()
In-Reply-To: <388B549C.A2C038D@ou.edu>
Message-ID: <Pine.SUN.3.91.1000124092228.10104F@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: dj-admin AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sun, 23 Jan 2000, David Cleaver wrote:

> fprintf(out, "%#x", array0[looper1][looper2]);
> where array0 contains unsigned char's
> 
> Anyway,  does the compiler actually think that 0xf is the same as 0x0f? 
> I personally think it should print out the leading zero

If you want the leading zero, use "%#0x" as your format specifier.  
`fprintf' cannot know what do you want it to do except by looking at
the format specifier that you provide.

> So, would the compiler be able to recognize if I chaged the array:
> from {0xf, 0xf, 0x1, 0x7} to {0xff17}?

You are mixing two different things: how a value of a 8-bit byte is 
printed, and how it is packed into a 32-bit int.  A value of 0xf (15 in 
decimal) can still occupy 8 bits, even if 4 bits are enough to express 
the value of 15.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019