which is about what I'd have expected due to the arguments to printf being evaluated before printf is called

I'm still not sure what you mean by that.

If you call foo($a + $b), perl will calculate $a + $b putting the result in a temporary scalar variable, and put that temporary scalar variable on the stack to call foo(). If you call foo($a), perl will put the scalar variable $a on the stack, and call foo().

In the case of printf("%s%n%.*s\n", $prefix, $stored_width, $limit, $postfix), we get (effectively) references to each of those variables on the stack (at the C level, they are just SV* pointers) - you know they have to be references, since printf needs to be able to write to $stored_width. At the point the printf implementation needs the next argument as a number, it'll ask the relevant scalar what its numeric value is; if it needs a string, it'll ask for that instead, etc.

Is that making it any clearer?


In reply to Re^3: How to use sprintf %n formatting pattern by hv
in thread How to use sprintf %n formatting pattern by ibm1620

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.