LWN.net Logo

GCC Explorer - an interactive take on compilation

GCC Explorer - an interactive take on compilation

Posted May 25, 2012 20:38 UTC (Fri) by mpr22 (subscriber, #60784)
In reply to: GCC Explorer - an interactive take on compilation by alankila
Parent article: GCC Explorer - an interactive take on compilation

An even more carefully designed API would allow you to do so rather than requiring you to.


(Log in to post comments)

GCC Explorer - an interactive take on compilation

Posted May 26, 2012 12:43 UTC (Sat) by alankila (subscriber, #47141) [Link]

Sure. I cold imagine a printf macro that just expands to static initialization of the format followed by use of that format. There's some good things to be said for brevity, and in seriousness I do not propose this. It is perfectly acceptable to waste CPU cycles and memory, because proportionally speaking they aren't in such a short supply.

GCC Explorer - an interactive take on compilation

Posted Jun 2, 2012 21:27 UTC (Sat) by vonbrand (subscriber, #4458) [Link]

Oh, come on. The compiler surely could figure out that this is printf, scan the format string and replace the whole printf("Look at this: %d %x\n", a, b) call by something along the lines of puts("Look at this: "); do_fmt_d(a); do_fmt_x(b); putchar('\n');. Probably pointless (if that is your performance bottleneck, you can do something along those lines yourself).

GCC Explorer - an interactive take on compilation

Posted Jun 3, 2012 5:37 UTC (Sun) by quotemstr (subscriber, #45331) [Link]

Your transformation isn't valid: consider multithreading. One printf will write to a stream as an atomic operation (enforced by internal stdio locks), but the output from discrete output functions may overlap.

GCC Explorer - an interactive take on compilation

Posted Jun 3, 2012 9:23 UTC (Sun) by dgm (subscriber, #49227) [Link]

That's why a naive coder with a optimizing compiler cannot beat a good coder. The compiler is bound by the precise semantics of the code, even if there are aspects of it that you don't care. The compiler has to care.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds