[Issue 22096] New: Can not get global struct member addresses at compile time

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 1 20:27:38 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22096

          Issue ID: 22096
           Summary: Can not get global struct member addresses at compile
                    time
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dbugs at yhzar.kellerspeicher.ch

Hi!

This report is based on the forum thread:
https://forum.dlang.org/thread/cjbjcuzsefvjryrjlflf@forum.dlang.org

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.

--


More information about the Digitalmars-d-bugs mailing list