From owner-freebsd-current Tue Jan 20 13:43:30 1998 Return-Path: Received: (from daemon@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA08670 for current-outgoing; Tue, 20 Jan 1998 13:43:30 -0800 (PST) (envelope-from owner-freebsd-current) Received: from hydrogen.nike.efn.org (d182-89.uoregon.edu [128.223.182.89]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA08662 for ; Tue, 20 Jan 1998 13:43:23 -0800 (PST) (envelope-from gurney_j@efn.org) Received: (from jmg@localhost) by hydrogen.nike.efn.org (8.8.7/8.8.7) id NAA14213; Tue, 20 Jan 1998 13:31:54 -0800 (PST) Message-ID: <19980120133154.34281@hydrogen.nike.efn.org> Date: Tue, 20 Jan 1998 13:31:54 -0800 From: John-Mark Gurney To: Terry Lambert Cc: ????????????? , current@FreeBSD.ORG Subject: Re: Nasty GCC bug? References: <199801202053.NAA25835@usr06.primenet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.69 In-Reply-To: <199801202053.NAA25835@usr06.primenet.com>; from Terry Lambert on Tue, Jan 20, 1998 at 08:53:41PM +0000 Reply-To: John-Mark Gurney Organization: Cu Networking X-Operating-System: FreeBSD 2.2.1-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ Sender: owner-freebsd-current@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk Terry Lambert scribbled this message on Jan 20: > > 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. actually... there is one for the short... didn't you read the man page? :) o The optional character h, specifying that a following d, i, o, u, x, or X conversion corresponds to a short int or unsigned short int ar- gument, or that a following n conversion corresponds to a pointer to a short int argument. but the char one is missing... > 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. yes... you specified minium field width.. therer is no way to limit the number of characters outputed from x... > 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. -- John-Mark Gurney Modem/FAX: +1 541 683 6954 Cu Networking P.O. Box 5693, 97405 Live in Peace, destroy Micro$oft, support free software, run FreeBSD