LWN.net Logo

GCC Explorer - an interactive take on compilation

GCC Explorer - an interactive take on compilation

Posted May 28, 2012 16:28 UTC (Mon) by gb (subscriber, #58328)
In reply to: GCC Explorer - an interactive take on compilation by gb
Parent article: GCC Explorer - an interactive take on compilation

err, typo s/and pushing each value to stack each time i am calling this function/instead of pushing each value to stack each time i am calling this function/


(Log in to post comments)

GCC Explorer - an interactive take on compilation

Posted May 28, 2012 16:51 UTC (Mon) by hummassa (subscriber, #307) [Link]

You seem to have forgotten something important: the compiler does not know if you want to retain the state from one call to the function to the next, and that would be an important side effect of static... and the reason why static (and static const) puts stuff on .data, as opposed to automatic (and automatic const) pushing values on the stack.

GCC Explorer - an interactive take on compilation

Posted May 28, 2012 21:09 UTC (Mon) by gb (subscriber, #58328) [Link]

Nope, i haven't forgotten this.

Compiler do know this perfectly, this static array is entirely inside function scope and it's trivial for compiler to find that static const case is absolutely same to plain const case, and that both are never used outside of scope of this function.

GCC Explorer - an interactive take on compilation

Posted May 29, 2012 18:53 UTC (Tue) by hummassa (subscriber, #307) [Link]

Anyway, arrays have to deal with many issues (aliasing, for instance) that preclude many optimization strategies; sometimes, the compiler programmers have to give some priority for the strategies that don't have to deal with that.

GCC Explorer - an interactive take on compilation

Posted May 29, 2012 9:41 UTC (Tue) by dgm (subscriber, #49227) [Link]

In C "const" does no imply any specific kind of storage. You can have register consts, static consts, auto consts, extern consts, and consts in the heap.

This is one of those places where C shows it's really a medium-level language, that gives you far more control over such little details than anything else.

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