How to get the address of a static struct?

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 9 20:53:21 PDT 2017


Thread local struct:

```D
module foobar;

struct Foo {
	int x;
}

Foo foo = Foo(8);

void main() {
	import std.stdio;
	writeln(&foo);
}
```

Global struct:

```D
module foobar;

struct Foo {
	int x;
}

__gshared Foo foo = Foo(8);

void main() {
	import std.stdio;
	writeln(&foo);
}
```

Compile time constant:

```D
module foobar;

struct Foo {
	int x;
}

enum FOO = Foo(8);

void main() {
	import std.stdio;
	Foo foo = FOO;
	writeln(&foo);
}
```


More information about the Digitalmars-d-learn mailing list