Date: Sat, 21 Jun 2003 11:44:41 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: abc@ai1.anchorage.mtaonline.net Cc: freebsd-questions <questions@freebsd.org> Subject: Re: is this a FBSD printf bug? Message-ID: <20030621104441.GA89537@happy-idiot-talk.infracaninophile.co.uk> In-Reply-To: <200306211014.h5LAECvr038054@en26.ai1.anchorage.mtaonline.net> References: <200306211014.h5LAECvr038054@en26.ai1.anchorage.mtaonline.net>
next in thread | previous in thread | raw e-mail | index | archive | help
--17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jun 21, 2003 at 10:14:12AM +0000, abc@ai1.anchorage.mtaonline.net w= rote: > i hope this isn't a question based on extreme > ignorance - i haven't programmed in C in a > long time, and i don't have another machine > to test this on. i can't understand why > the output of the following code produces > "ints" when given variables of type "char", > so it looks like a bug to me ... Nope -- this is a C language FAQ (See http://www.faqs.org/faqs/C-faq/faq/, particularly section 15). Neither is it FreeBSD specific. If you pass arguments to a varargs function, like printf(3), then they will get type promoted. In this case 'char' is promoted to 'int'. The reason the results you're seeing don't match up to your expectations is that the 'char' type is signed, and you seem to want to be using an unsigned type. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way PGP: http://www.infracaninophile.co.uk/pgpkey Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK --17pEHd4RhPHOinZp Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE+9DcZdtESqEQa7a0RAiPWAJwJjhtwFr783GzxQUW7laTcjSnmEACfa5wn ZNkKod7lKto+AbrYhjSv8ek= =Tkfd -----END PGP SIGNATURE----- --17pEHd4RhPHOinZp--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030621104441.GA89537>