static static

Bill Baxter wbaxter at gmail.com
Tue Nov 10 13:25:48 PST 2009


On Tue, Nov 10, 2009 at 1:15 PM, bearophile <bearophileHUGS at lycos.com> wrote:
> Yigal Chripun:
>
>> 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.
>
> Maybe you have misunderstood, or I have explained the things badly. So I explain again.
>
> I have seen that LDC (when it performs link-time optimization, that's not done in all situations) keeps just one copy of constants inside the binary even if such constants are present in more than one template instance. In the situations where LTO is available I think this doesn't cause problems.
>
> Then I am half-seriously proposing a syntax like:
> T foo(T)(T x) {
>  static static int y;
>  // ...
> }
>
> Where the y is now static to (shared among) all instances of the templated function foo. This may be a little error-prone and maybe not that useful, but again here the compiler doesn't change the semantics of the program, because using a double static keyword the programmer has stated such intention.

Make it "super static" and I'm sold.  :-)

Just kidding.  It's never occurred to me to want something like that.
I guess I'd probably just use a global variable.  And maybe that's for
the better since it screams out more clearly that something strange is
going on.  And maybe gets the developer to rethink the design one more
time before going down that path.

--bb



More information about the Digitalmars-d mailing list