Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: printf format specifier changes Date: Tue, 07 Jul 2015 20:42:11 -0700 Organization: None to speak of Lines: 35 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="22432"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hIlhWZI/nD5QE+Lqe7jn+" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:vbnWXu+jDJQSic1nEuj73cAYVjQ= sha1:OBS11O3lKnXsyziEoa5yD8q/M24= Xref: csiph.com comp.lang.c:64893 Les Cargill writes: > Bartc wrote: >> On 06/07/2015 17:04, Rick C. Hodgin wrote: >>> In 2015, what suggestions would you have for changing anything about >>> the format specifiers used in the printf functions? Leave them as >>> they are? Or change this or that about them? >> >> In 2015, the whole notion of having to tell a compiler what it already >> knows - the type of the values it's printing - is outdated. >> > > No, it is not. > > Example 1: > > char *s = something(); > > printf(":%s: 0x%08x\n",s,(int)s); > > Every. Single. Attempt. To improve on this. Fails. Repeatedly. %x requires an unsigned int, not an int. But I would write that as: printf(":%s: %p\n", s, (void*)s); (It can be argued that the cast is not needed in this case, but it's easier to be consisten.) [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"