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, 0 replies; 3+ messages in thread
From: Clem Cole @ 2019-12-31 16:40 UTC (permalink / raw)
  To: Doug McIlroy; +Cc: The Eunuchs Hysterical Society

[-- Attachment #1: Type: text/plain, Size: 734 bytes --]

On Mon, Dec 30, 2019 at 11:24 PM Doug McIlroy <doug@cs.dartmouth.edu> wrote:

> The use of %% to designate a literal % in printf is not
> a recent convention. It was defined in K&R, first edition.
>
FWIW, I still have an old (fading) copy of the galley proofs for the first
edition.  Page 147 (*Chapter 7 - Input and Output, Section 7.3 Formatted
Output - Printf*) first full paragraph on the page:

If the character after the % is not a conversion character, that character
is printed: thus % may be printed by %%.



>
> 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.
>
>

[-- Attachment #2: Type: text/html, Size: 1631 bytes --]

^ 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).