static static

Yigal Chripun yigal100 at gmail.com
Tue Nov 10 12:37:03 PST 2009


bearophile wrote:
> When I convert a function to a templated function (for example
> because I know the value of an argument at compile time, so using a
> template gives me a poor's man partial compilation) the static
> variables get duplicated for each instance of the function template,
> and I may need to use true global variables/constants (but if you use
> link-time optimization then LDC is able to remove such shared
> constants). So I was thinking about a "static static" attribute that
> avoid moving the statics to globals. Is this a useless idea?
> 
> Bye, bearophile

Regardless of usefulness (or good design) of such variables, this sounds
extremely dangerous. The compiler must not change semantics of the
program based on optimization. optimizing away such variables most
definitely alters the semantics.

I wonder, how do other languages treat static variables inside templated 
functions?



More information about the Digitalmars-d mailing list