The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* Re: [TUHS] pic anomalies
@ 2019-12-31  4:12 Doug McIlroy
  0 siblings, 0 replies; 3+ messages in thread
From: Doug McIlroy @ 2019-12-31  4:12 UTC (permalink / raw)
  To: tuhs

According to K&R the behavior of % followed by something
unexpected is undefined. So the behavior of Ralph's example
is officially an accident. (It's uncharacteristic of Dennis
to have defined printf so that there was no guaranteed way
to get a literal % into a format.)

Doug

------------------------------------------------

Ralph Corderoy wrote:

    $ printf '%s\n' \
        .PS 'print sprintf("%.17g %.0f% % %%", 3.14, 42, 99)' .PE |
    > pic >/dev/null
    3.1400000000000001 42% % %%

Though that may seem odd to our modern C-standardised eyes, it's
understandable in that if it isn't a valid %f, etc., format specifier
then it's a literal percent sign.

^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: [TUHS] pic anomalies
@ 2019-12-31  4:24 Doug McIlroy
  2019-12-31 16:40 ` Clem Cole
  0 siblings, 1 reply; 3+ messages in thread
From: Doug McIlroy @ 2019-12-31  4:24 UTC (permalink / raw)
  To: tuhs

The use of %% to designate a literal % in printf is not
a recent convention. It was defined in K&R, first edition.

Doug

Ralph Cordery wrote:

Though that may seem odd to our modern C-standardised eyes, it's
understandable in that if it isn't a valid %f, etc., format specifier
then it's a literal percent sign.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-31 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-31  4:12 [TUHS] pic anomalies Doug McIlroy
2019-12-31  4:24 Doug McIlroy
2019-12-31 16:40 ` Clem Cole

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).