This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Proposal for printf functionality enchancement


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]