Re: Can not get struct member addresses at compile time

2021-06-17 Thread Doeme via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 23:20:26 UTC, Ali Çehreli wrote: Thank you, both. It still rules out an address at "compile time" in general. For example, we cannot use such an address when instantiating a template, or static array length, etc. And if I understand it correctly, there must be a p

Re: Can not get struct member addresses at compile time

2021-06-16 Thread Doeme via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 22:16:54 UTC, H. S. Teoh wrote: The compiler does not (and cannot) know. But the runtime dynamic linker can, and does. The two are bridged by the compiler emitting a relocatable symbol for the address of the global variable, with a table of relocations (offsets i

Re: Can not get struct member addresses at compile time

2021-06-16 Thread Doeme via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 21:42:41 UTC, Ali Çehreli wrote: On 6/16/21 8:47 AM, Doeme wrote: > On Wednesday, 16 June 2021 at 13:36:07 UTC, Ali Çehreli wrote: >> On 6/16/21 2:27 AM, Doeme wrote: >> >> > How does one get the address of a struct member? >> >> Here is an experiment with offsetof

Re: Can not get struct member addresses at compile time

2021-06-16 Thread Doeme via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 11:56:31 UTC, Mike Parker wrote: https://dlang.org/spec/pragma.html#crtctor Very interesting, thanks for the hint! This is definitely a viable solution, though if there's a way to let the linker determine the pointer address, that'd be even better. In C, it's a

Re: Can not get struct member addresses at compile time

2021-06-16 Thread Doeme via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 13:36:07 UTC, Ali Çehreli wrote: On 6/16/21 2:27 AM, Doeme wrote: > How does one get the address of a struct member? Here is an experiment with offsetof and opDispatch: Cool stuff! I actually tried a very similar approach once, but it did not work out, since the

Can not get struct member addresses at compile time

2021-06-16 Thread Doeme via Digitalmars-d-learn
Hi! I'm currently investigating why I can not take the address of a static struct-element at compile time (afaik the linker should be able to resolve this, and doing the identical thing in C works...) ```d struct Foo{ ubyte bar; } __gshared Foo foo; void* baz = \&foo; //works void* ba