Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe01.iad.POSTED!00000000!not-for-mail Newsgroups: comp.std.c Subject: Re: PRI* considered harmful User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (berkeley-unix) References: <87mxgqhk3x.fsf@once.weird.com> <8762ndhnfs.fsf@once.weird.com> <87oc15g10i.fsf@once.weird.com> <87zkkpef5z.fsf@once.weird.com> From: "Greg A. Woods" X-Face: .}E4CW({2'v<\JefgY&(9#RJD?~_7.KTC$+RklqwlB/<)^)~X0i*J?m)SXpHA8'9FHn5Fz*eVTH5=_C>]XK#"dLOyD`#tbEh1_8v-hwwR{.X)+b-!\4mM] 1HqG#"@VSI$1MNvRk\4>qsCclW|Ns4V/2poz=gS-+~m8\%5eVq]a\3.>T>U/f8A Message-ID: <87mxgpe84b.fsf@once.weird.com> Cancel-Lock: sha1:phLihB3hM9y4fmhfDCm2QTa1+Ag= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 48 NNTP-Posting-Host: 24.67.98.78 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: newsfe01.iad 1310097508 24.67.98.78 (Fri, 08 Jul 2011 03:58:28 UTC) NNTP-Posting-Date: Fri, 08 Jul 2011 03:58:28 UTC Date: Thu, 07 Jul 2011 20:58:28 -0700 Xref: x330-a1.tempe.blueboxinc.net comp.std.c:638 James Kuyper 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. > The right way to #define PRI32d: #define it to be a format specification > which is NOT a mismatch for the corresponding promoted type; no cast > required. Someone should try this on some GNU/Linux variants for me -- I think from my manual inspection of glibc header sources online that you'll get a warning (if you turn on the right warning flags).... It works OK on NetBSD and on OS X. > The right way to use PRI32d (no cast required): > int32_t value; > // set value > printf("value:%" PRI32d "\n", value); Some code does that, but most folks don't seem to be PL/1-heads, i.e. that pedantic about how many bits they want. Most folks want an "int", or maybe a "long" for bigger values. They can't be bothered to worry about numbers of bits. > An implementation that can't be bothered to define the PRI* macros > correctly cannot be trusted to implement your proposed printf() > enhancements, either. Sigh.... >>>> Also, I repeat, C99 strftime() is unable to print the value of a time_t >>>> as an integer representation of seconds since the epoch of time_t. ... > > 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. :-) -- Greg A. Woods RoboHack living on the edge http://www.robohack.ca/