static variables for non-constant expressions?
Stewart Gordon
smjg_1998 at yahoo.com
Mon Apr 11 14:15:54 PDT 2011
On 11/04/2011 02:37, Jonathan M Davis wrote:
<snip>
>> I don't know the background of how static variables really work, so is
>> there a good reason why the first function can't work like the one below
>> it?
>
> They have to be calculated at compile time so that ordering doesn't matter. If
> the order mattered, then you get into dependency problems or risk using
> undefined variables. Languages like C++ and Java have problems with that.
<snip>
I recall reading that in C++, static variables are initialised on first call. Which would
have to mean that it does something like that internally.
But I might be imagining it. I'll have to experiment.
Can you give an example of the dependency problems this might lead to?
Stewart.
More information about the Digitalmars-d-learn
mailing list