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