[TUHS] pic anomalies

Doug McIlroy doug at cs.dartmouth.edu
Tue Dec 31 14:12:44 AEST 2019


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.


More information about the TUHS mailing list