Why is a static struct's dtor called at the exit of a function?

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 22 13:14:44 PDT 2011


> On Fri, 22 Jul 2011 02:57:38 -0400, Diego Canuhé <canuhedc at gmail.com>
> 
> wrote:
> > thanks ;)
> 
> Don't feel bad, static is probably the most abused keyword in D and C++.
> It has about 3 or 4 meanings depending on context.

The interesting thing is that in C++, there's actually a definition for static 
which covers _all_ of its uses. Unfortunately, at the moment, I can't remember 
it exactly (something about global lifetime and limited scoped, I think). But 
with the change to thread-local as the default in D and the addition of static 
constructors and what static does to nested classes and functions, I don't 
think that that definition applies to D. It was a relatively useless 
definition anyway, since you really need to know in detail how static works in 
each case rather than have a definition which is vague enough to cover a 
variety of cases which most anyone would consider completely unrelated. It was 
pretty cool though that there was a definition which covered all of the cases. 
I just wish that I could remember what it was...

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list