This is the mail archive of the
mailing list for the glibc project.
Re: Proposal for printf functionality enchancement
Daniel Jacobowitz <firstname.lastname@example.org> writes:
> Here's an example:
> int foo;
> static int bar1(void)
> return foo;
> static int bar2(void)
> return printf ("%d\n", foo);
> The compiler can optimize based on the knowledge that bar1 doesn't
> modify foo. It could do the same for bar2, if it knew that there was
> no way for printf to do so. Which there isn't, with the exceptions of
> %n (easy to check statically), and custom format characters (basically
> impossible to check).
Customer formaters work after printf/etc. have been called ... so foo
can be modified at that point, but the argument that is a copy of foo
passed to printf could not be altered.
Or maybe you mean that if you do "int x = bar2(); int y = bar2();"
you can optimize the second call (I could see this if you used
sprintf() with a local char). But that seems far fetched, and again
would be solved via. GCC understanding the mini-language properly.
James Antill -- email@example.com
Need an efficient and powerful string library for C?