what's the scope of a static variable inside a local function?

Steven Schveighoffer schveiguy at yahoo.com
Fri Jan 5 22:17:47 UTC 2018


On 1/5/18 5:07 PM, Jonathan M Davis wrote:

> but doesn't print out anything about main or f. I don't know if that's a bug
> or not, since the only way that I can think of to make it work would be to
> have the compiler invisibly add a static destructor to the module to clean
> them up, and that would cause other problems. It's just not something that
> I've ever thought about before.

Hm... if you counted on thread termination to clean up a resource, then 
it's definitely a bug.

Static dtors would be the most effective way to clean it up, as the 
mechanism already exists, but they would have to be marked as 
independent. And of course, -betterC couldn't do it, which means RAII 
would be broken when compiled that way.

-Steve


More information about the Digitalmars-d-learn mailing list