From owner-freebsd-current Tue Jan 20 12:54:09 1998 Return-Path: Received: (from daemon@localhost) by hub.freebsd.org (8.8.8/8.8.8) id MAA04384 for current-outgoing; Tue, 20 Jan 1998 12:54:09 -0800 (PST) (envelope-from owner-freebsd-current) Received: from smtp03.primenet.com (smtp03.primenet.com [206.165.6.133]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id MAA04318 for ; Tue, 20 Jan 1998 12:53:58 -0800 (PST) (envelope-from tlambert@usr06.primenet.com) Received: (from daemon@localhost) by smtp03.primenet.com (8.8.8/8.8.8) id NAA19479; Tue, 20 Jan 1998 13:53:51 -0700 (MST) Received: from usr06.primenet.com(206.165.6.206) via SMTP by smtp03.primenet.com, id smtpd019460; Tue Jan 20 13:53:48 1998 Received: (from tlambert@localhost) by usr06.primenet.com (8.8.5/8.8.5) id NAA25835; Tue, 20 Jan 1998 13:53:41 -0700 (MST) From: Terry Lambert Message-Id: <199801202053.NAA25835@usr06.primenet.com> Subject: Re: Nasty GCC bug? To: ache@nagual.pp.ru (=?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?=) Date: Tue, 20 Jan 1998 20:53:41 +0000 (GMT) Cc: tlambert@primenet.com, current@FreeBSD.ORG In-Reply-To: from "=?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?=" at Jan 20, 98 10:47:03 pm X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk > On Tue, 20 Jan 1998, Terry Lambert wrote: > > > What is happening is that the value is being sign-extended to int > > when it is pushed on the stack. > > It is absolutely no bug here, it is THE RULE. > > All types smaller than int promotes to int in any expression, and signed > types promotes _with_ sign extension. Function argument is an expression. I typed the wrong subject. My complaint was about how %02x worked with sign extended character values. As I pointed out, not doing the extension would break %d, and it's the fact that printf didn't know it was a character value that had been sign extended instead of an int value that was the bug. %x expects and int, %lx expects a long. There is not one that expects a short or a char. Also, my field width limits are being ignored. I kind of expected it to print out a field limit's worth of hex characters, starting at the lsb. The problem initially showed in a program that sscanf'ed into an int of %2x, assigned a character array valued to the int, and then tried to printf the char value to get back out what it scanned in. The resulting output not matching the input was unexpected, since it's sort of normal to expect that printf/scanf are inverse functions. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.