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

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Jan 6 01:21:10 UTC 2018


On Friday, January 05, 2018 17:17:47 Steven Schveighoffer via Digitalmars-d-
learn wrote:
> 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.

Yeah, so I don't know. Digging around on bugzilla though, it looks like a
similar problem was already reported for module-level variables, and Andrei
commented that it didn't work with static variables either but wasn't sure
what the spec said on the matter:

https://issues.dlang.org/show_bug.cgi?id=14650

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list