Scholarly Resources for CompSci Undergrads

C Programming Language

Errata lists for K&R II

Correction to Table B-1 (printf Conversions)

Both Tanmoy Bhattacharya and Dan Pop pointed out a mistake in Table B-1 (on p. 244) about printf conversions. Tanmoy provided a citation to the standard. Dan explained where the confusion may have come from.

Tanmoy Bhattacharya's Contribution
Newsgroups: comp.lang.c
From: Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov>
Subject: Re: Posted code MUST compile
Date: 14 Feb 1997 14:35:43 -0700
Organization: Los Alamos National Laboratory
Lines: 37
Distribution: inet
Message-ID: <y84tff840g.fsf@qcd.lanl.gov>
References: <5dqsbs$i8j$3@brokaw.wa.com> <5dvbli$6ma@news1.mnsinc.com>
	<y8hgjg8bih.fsf@qcd.lanl.gov> <5e259b$4mg@hnssysb.hns.com>
X-Newsreader: Gnus v5.3/Emacs 19.34

sthuang@hns.com (Steven Huang) writes:
<snip>
> >> Eh?  The %x format displays its 'int' parameter in unsigned
> >                                   ^^^
> >unsigned int according to the standard.
> 
> I thought so, too.  Table B-1 of K&R2 (where I copied from) however said
> 'int', converted to unsigned hexadecimal notation.  My manpage said:
> 
>     d,i,o,u,x,X    The integer arg is converted to signed decimal (d
>                    and i are identical), unsigned octal (o), decimal
>                    (u), or hexadecimal notation (x and X), respectively;
> 
> I think we need a lawyer now.  :)

No, the standard is at hand, and clearly states that it is undigned int:

d,i	The int argument ....
o,u,x,X The unsigned int argument ...

(7.9.6.1)

I vaguely remember there was a defect report that the standard fails
to mention that not passing the `correct' type leads to undefined
behaviour and the committee clarified that it was indeed undefined,
but I am sure c.l.c is not the right place for nit picks at that
level.

Cheers
Tanmoy
-- 
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
Dan Pop's Contribution
Newsgroups: comp.lang.c
From: Dan.Pop@cern.ch (Dan Pop)
Subject: Re: Posted code MUST compile
Message-ID: <danpop.855943185@news.cern.ch>
Sender: news@news.cern.ch (USENET News System)
Organization: CERN European Lab for Particle Physics
X-Newsreader: NN version 6.5.0 #18 (NOV)
References: <5dqsbs$i8j$3@brokaw.wa.com> <5dvbli$6ma@news1.mnsinc.com> <y8hgjg8bih.fsf@qcd.lanl.gov> <5e259b$4mg@hnssysb.hns.com>
Distribution: inet
Date: Fri, 14 Feb 1997 17:59:45 GMT
Lines: 36

In <5e259b$4mg@hnssysb.hns.com> sthuang@hns.com (Steven Huang) writes:

>In article <y8hgjg8bih.fsf@qcd.lanl.gov> Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov> writes:
>>huang@mnsinc.com (Szu-Wen Huang) writes:
>
>>> Eh?  The %x format displays its 'int' parameter in unsigned
>>                                   ^^^
>>unsigned int according to the standard.
>
>I thought so, too.  Table B-1 of K&R2 (where I copied from) however said
>'int', converted to unsigned hexadecimal notation.  My manpage said:
>
>    d,i,o,u,x,X    The integer arg is converted to signed decimal (d
>                   and i are identical), unsigned octal (o), decimal
>                   (u), or hexadecimal notation (x and X), respectively;
>
>I think we need a lawyer now.  :)

No need for a lawyer, the standard is right, by definition, even when
it's wrong :-)

The origin of the confusion has to be searched in the history of the
standard itself.

As late as 1988 (i.e. by the time K&R2 was printed) the draft said:

d, i, o, u, x, X   The int argument is converted to signed decimal
		   (d or i), unsigned octal (o), unsigned decimal (u),
		   or unsigned hexadecimal notation (x or X); ...

Dan
--
Dan Pop
CERN, IT Division
Email: Dan.Pop@cern.ch 
Mail:  CERN - PPE, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland

http://www.csd.uwo.ca/~jamie/C/KR/Errata/B-1.html
J. Blustein