Bug 22096 – Can not get global struct member addresses at compile time

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-01T20:27:38Z
Last change time
2024-12-13T19:17:31Z
Assigned to
No Owner
Creator
Doeme
Moved to GitHub: dmd#19959 →

Comments

Comment #0 by dbugs — 2021-07-01T20:27:38Z
Hi! This report is based on the forum thread: https://forum.dlang.org/thread/[email protected] I'm currently investigating why I can not take the address of a static struct-element at compile time. struct Foo{ int bar; } __gshared Foo foo; void *foo_ptr = &foo; // Works void *bar_ptr = &foo.bar; // Error: static variable `foo` cannot be read at compile time The D-Compiler passes the relocation of *foo_ptr down to the linker, but relocations plus an offset seem to not work. If I'd have to guess I'd say that this is a side-effect of all member accesses possibly being function calls.
Comment #1 by robert.schadek — 2024-12-13T19:17:31Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19959 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB