Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Jan 1998 13:31:54 -0800
From:      John-Mark Gurney <gurney_j@efn.org>
To:        Terry Lambert <tlambert@primenet.com>
Cc:        ????????????? <ache@nagual.pp.ru>, current@FreeBSD.ORG
Subject:   Re: Nasty GCC bug?
Message-ID:  <19980120133154.34281@hydrogen.nike.efn.org>
In-Reply-To: <199801202053.NAA25835@usr06.primenet.com>; from Terry Lambert on Tue, Jan 20, 1998 at 08:53:41PM %2B0000
References:  <Pine.BSF.3.96.980120224412.28008A-100000@lsd.relcom.eu.net> <199801202053.NAA25835@usr06.primenet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980120133154.34281>