Proposal for printf functionality enchancement

James Antill nevyn-glibc-alpha@and.org
Wed Oct 19 18:11:00 GMT 2005


Daniel Jacobowitz <drow@false.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 -- james@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/



More information about the Libc-alpha mailing list