Static struct?
user1234
user1234 at 12.de
Wed Apr 24 21:27:22 UTC 2019
On Wednesday, 24 April 2019 at 21:12:10 UTC, JN wrote:
> I noticed a construct I haven't seen before in D when reading
> the description for automem -
> https://github.com/atilaneves/automem
>
> static struct Point {
> int x;
> int y;
> }
>
>
> What does "static" do in this case? How does it different to a
> normal struct?
It's like if it's declared at the global scope, meaning that it
doesn't know the context and cant access, if declared in a
function, the stack frame. Now dependeding on the location,
static can be a noop.
module foo;
static struct One {} // noop
void bar()
{
int i;
static struct Two { void stuff(){ i = 42:} } // error
}
void baz()
{
int i;
struct Three { void stuff(){ i = 42:} } // ok
}
More information about the Digitalmars-d-learn
mailing list