Accessing static data of functions

Timon Gehr timon.gehr at gmx.ch
Tue Oct 19 11:12:12 UTC 2021


On 19.10.21 10:31, Mike Parker wrote:
> On Tuesday, 19 October 2021 at 08:15:01 UTC, Ogi wrote:
>>
>> What are we talking about is not a game but an engine to be used for 
>> making different games, potentially by people other than me. So this 
>> is a limitation that the users will have to be aware of and work 
>> around it, and failing to do so will result in silent bugs in their 
>> code because there’s no way to enforce it at compile time.
> 
> Personally, this isn't something I would expect, nor would I worry about 
> it. Static variables in functions are generally there because they are 
> scoped to that function, to be used within that function over the run 
> time of the program. There shouldn't be any reason whatsoever for them 
> to be accessible outside the function.
> 
> The idea that you are even considering serializing them is just a 
> foreign concept to me. If I wanted to make something available to a 
> serializer, I wouldn't declare it inside a function. I'd put it at 
> module scope, or in an aggregate. I'm not saying no one would ever think 
> of it (you obviously did), but in 25 years of following various online 
> programming communities (C, Java, D, game development, etc.) I can't 
> recall seeing anyone bring it up before now. I can't imagine it would be 
> common enough to be an issue.

The OP has a well-motivated use case. I don't understand at all why you 
are being this dismissive. The inability to serialize static variables 
scoped inside functions is clearly an arbitrary limitation that should 
be lifted.


More information about the Digitalmars-d mailing list