Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: [incorrectly implementd] PRI* considered harmful |
| Date | 2011-07-09 06:38 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <iv9b34$uvi$1@dont-email.me> (permalink) |
| References | (6 earlier) <87zkkpef5z.fsf@once.weird.com> <iv5qd4$f26$1@dont-email.me> <87mxgpe84b.fsf@once.weird.com> <iv6qdm$ei8$1@dont-email.me> <878vs8dm52.fsf@once.weird.com> |
On 07/09/2011 02:05 AM, Greg A. Woods wrote:
> James Kuyper <jameskuyper@verizon.net> writes:
>>
>> On 07/07/2011 11:58 PM, Greg A. Woods wrote:
>>> James Kuyper <jameskuyper@verizon.net> writes:
>>>>
>>>> The right way to warn about mismatches: only warn when there's an actual
>>>> mismatch.
>>>
>>> It is an "actual" mis-match -- at least if you intend your code to be
>>> portable.
>>
>> For every conforming implementation of C, PRI32d must be a correct match
>> to whichever type int32_t represents in that implementation. While
>> implementations are permitted to issue diagnostics for any reason they
>> like ("warning: identifiers containing 'z' make me feel fuzzy!"), an
>> implementation which diagnoses the correct match that PRI32d must have
>> with int32_t has low QoI because it's wasting the developer's time.
>
> I'm explicitly not talking about the ideal world where every
> implementation is conforming!
The title of your thread was "PRI* considered harmful"; this title
apparently incorrectly reflects your concerns, I've corrected it in this
message.
"Incorrectly implemented" anything is (almost always, but I'm sure there
are exceptions) a problem, but it's not a problem with the feature being
incorrectly implemented, it's a problem with the incorrect
implementation. Incorrectly implemented "%ld" formats would also be a
problem; but not a problem with the standard that specifies what correct
implementation of those formats means.
The problem you're running into is PRECISELY the problem that the PRI*
macros were designed to solve. They are correctly designed to solve it
(though excessively clumsy, in my opinion). The standard's specification
mandates that they solve it. Defining them in such a way as to actually
solve the problem is trivial; it requires true idiocy to implement them
incorrectly (though I would not recommend saying so to the person that
you ask to fix the problem). Any failure of those macros to be correctly
defined can be easily corrected by any implementor that actually cares
enough to bother doing so. If you've actually reported such
non-conformance to an implementor, and had your complaint ignored, that
would be worth complaining about (though your complaint should be lodged
in a forum specific to that implementation, not here).
But there's no point in complaining about a feature of the standard on
the basis of the behavior of a system that fails to conform to the
specifications of the standard for that feature.
...
>> Then why are they using int32_t? They only need the PRI* macros if they
>> choose to use the new size-named types.
>
> Because people love to use new features, but when those features are not
> really well documented, and when they can easily lead to such problems,
> those features might cause more harm than good. Read some real code
> (e.g. do some internet searches on *PRI* and *FMT* to find examples) and
> see for yourself.
People misuse "long int", too. That doesn't mean that "long int" has
something wrong with it.
>>>> Well, of course not. For that you use
>>>> printf("seconds since epoch:%.0f\n", difftime(value,epoch));
>>>
>>> Decades of unix tradition flushed down the drain by C99. :-)
>>
>> What tradition are you talking about?
>
> The tradition of course that time_t is, always has been, and always will
> be, an _integer_ number of seconds since the epoch.
And what has C99 done to flush that down the drain? Code which makes
that assumption is precisely as non-portable in C99 as it was in C90,
but on the implementations where it's non-portable assumptions are
correct, it will work just as well in C99 as in C90. In point of fact,
C99's new [u]intmax_t and the corresponding new printf() format
specifiers make it possible to write code embodying that unportable
assumption in as widely portable a fashion as possible.
>> What you've specified is not something I can see any point in printing
>> out,
>
> Assumptions, assumptions, assumptions! You know what they say about
> assumptions! :-)
Yes, I know - and it's complete nonsense. It's impossible to think
without making assumptions; the best you can do is to be aware of which
assumptions you make, to avoid making unnecessary assumptions, and to
make sure that when it is necessary to make assumptions (as is
inevitably the case), that they are as well justified as possible.
All of which is completely irrelevant to what I said; I made no
assumptions, I just don't know of a good reason for printing them out,
except for debugging purposes, and most debuggers I'm familiar with
don't require you to provide printf() formats. I use debugging printf()s
all the time, but it's not exactly difficult to get this one right;
you're just making it difficult by insisting on approaching the problem
incorrectly, and then complaining about the fact that it's not the right
approach.
--
James Kuyper
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-06 19:58 -0700
Re: PRI* considered harmful William Ahern <william@wilbur.25thandClement.com> - 2011-07-06 20:38 -0700
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-06 22:26 -0700
Re: PRI* considered harmful Jens Gustedt <Jens.Gustedt@loria.fr> - 2011-07-07 08:52 +0200
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-07 14:11 -0700
Re: PRI* considered harmful Jens Gustedt <Jens.Gustedt@loria.fr> - 2011-07-08 11:58 +0200
Re: PRI* considered harmful lawrence.jones@siemens.com - 2011-07-07 17:58 -0400
Re: PRI* considered harmful Jens Gustedt <Jens.Gustedt@loria.fr> - 2011-07-08 12:02 +0200
Re: PRI* considered harmful lawrence.jones@siemens.com - 2011-07-07 17:57 -0400
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-07 15:42 -0700
Re: PRI* considered harmful lawrence.jones@siemens.com - 2011-07-08 08:56 -0400
Re: PRI* considered harmful James Kuyper <jameskuyper@verizon.net> - 2011-07-07 06:36 -0400
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-07 12:59 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-07 14:12 -0700
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-07 15:49 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-07 16:46 -0700
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-07 18:26 -0700
Re: PRI* considered harmful James Kuyper <jameskuyper@verizon.net> - 2011-07-07 22:35 -0400
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-07 20:58 -0700
Re: PRI* considered harmful Wojtek Lerch <wojtek_l@yahoo.ca> - 2011-07-08 00:28 -0400
Re: PRI* considered harmful James Kuyper <jameskuyper@verizon.net> - 2011-07-08 07:41 -0400
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-08 23:05 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 00:50 -0700
Re: [incorrectly implementd] PRI* considered harmful James Kuyper <jameskuyper@verizon.net> - 2011-07-09 06:38 -0400
Re: PRI* considered harmful Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2011-07-09 21:07 +0200
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-08 09:52 -0700
Re: PRI* considered harmful Richard Kettlewell <rjk@greenend.org.uk> - 2011-07-08 11:45 +0100
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-08 23:14 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 00:47 -0700
Re: PRI* considered harmful Richard Kettlewell <rjk@greenend.org.uk> - 2011-07-09 10:51 +0100
Re: PRI* considered harmful James Kuyper <jameskuyper@verizon.net> - 2011-07-09 06:43 -0400
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-08 09:49 -0700
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-08 23:24 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 00:45 -0700
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-09 16:18 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 18:57 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-13 09:37 -0700
Re: PRI* considered harmful James Kuyper <jameskuyper@verizon.net> - 2011-07-09 06:46 -0400
Re: PRI* considered harmful Harald van Dijk <truedfx@gmail.com> - 2011-07-09 08:09 -0700
Re: PRI* considered harmful Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-11 16:00 +0300
Re: PRI* considered harmful Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2011-07-09 20:59 +0200
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 12:22 -0700
Re: PRI* considered harmful Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2011-07-09 21:32 +0200
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 12:54 -0700
Re: PRI* considered harmful Marcin Grzegorczyk <mgrzegor@poczta.onet.pl> - 2011-07-09 23:39 +0200
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-09 16:56 -0700
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-09 16:52 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 18:53 -0700
Re: PRI* considered harmful Jens Gustedt <Jens.Gustedt@loria.fr> - 2011-07-10 14:12 +0200
Re: PRI* considered harmful Marcin Grzegorczyk <mgrzegor@poczta.onet.pl> - 2011-07-11 20:22 +0200
Re: PRI* considered harmful Jens Gustedt <Jens.Gustedt@loria.fr> - 2011-07-10 13:57 +0200
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-09 16:49 -0700
Re: PRI* considered harmful Jens Schweikhardt <usenet@schweikhardt.net> - 2011-07-19 19:28 +0000
Re: PRI* considered harmful Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-07 14:13 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 01:04 -0700
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-09 17:23 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-09 19:03 -0700
Re: PRI* considered harmful Marcin Grzegorczyk <mgrzegor@poczta.onet.pl> - 2011-07-11 20:40 +0200
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-11 11:56 -0700
Re: PRI* considered harmful Marcin Grzegorczyk <mgrzegor@poczta.onet.pl> - 2011-07-11 21:40 +0200
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-11 13:16 -0700
Re: PRI* considered harmful Marcin Grzegorczyk <mgrzegor@poczta.onet.pl> - 2011-07-11 23:29 +0200
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-11 14:46 -0700
Re: PRI* considered harmful "Greg A. Woods" <woods@robohack.org> - 2011-07-12 22:18 -0700
Re: PRI* considered harmful Keith Thompson <kst-u@mib.org> - 2011-07-13 09:00 -0700
Re: PRI* considered harmful Richard Kettlewell <rjk@greenend.org.uk> - 2011-07-09 20:30 +0100
csiph-web