From owner-freebsd-questions@FreeBSD.ORG Sat Jun 21 03:45:01 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9DC8637B401 for ; Sat, 21 Jun 2003 03:45:01 -0700 (PDT) Received: from smtp.infracaninophile.co.uk (ns0.infracaninophile.co.uk [81.2.69.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id AB48B43FE3 for ; Sat, 21 Jun 2003 03:44:59 -0700 (PDT) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost [127.0.0.1]) h5LAiho2003328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 21 Jun 2003 11:44:46 +0100 (BST) (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost)h5LAig11003235; Sat, 21 Jun 2003 11:44:42 +0100 (BST) (envelope-from matthew) Date: Sat, 21 Jun 2003 11:44:41 +0100 From: Matthew Seaman To: abc@ai1.anchorage.mtaonline.net Message-ID: <20030621104441.GA89537@happy-idiot-talk.infracaninophile.co.uk> Mail-Followup-To: Matthew Seaman , abc@ai1.anchorage.mtaonline.net, freebsd-questions References: <200306211014.h5LAECvr038054@en26.ai1.anchorage.mtaonline.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline In-Reply-To: <200306211014.h5LAECvr038054@en26.ai1.anchorage.mtaonline.net> User-Agent: Mutt/1.5.4i X-Spam-Status: No, hits=-11.2 required=5.0 tests=AWL,BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,PGP_SIGNATURE_2, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT autolearn=ham version=2.55 X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) cc: freebsd-questions Subject: Re: is this a FBSD printf bug? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Jun 2003 10:45:01 -0000 --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--