can not take const struct member address at CTFE , is this a bug?
Ruby The Roobster
rubytheroobster at yandex.com
Wed Sep 14 00:40:38 UTC 2022
On Tuesday, 13 September 2022 at 11:16:55 UTC, test123 wrote:
> ```d
> struct c { uint a, b;}
> __gshared const c d = { 3, 4};
> __gshared const e = &d.a;
> ```
>
> ./test.d(4): Error: expression `&c(3u, 4u).a` is not a constant
>
>
> I need this to work around C struct array member like this:
>
> ```c
> struct c {
> uint32_t a, b;
> uint32_t[] arr;
> }
> ```
>
> If I can take const object member address as __gshared const,
> then the problem is fixed.
>
>
> Or if I can force cast the const object pointer into other
> type, will work be able to work this around. (but not work)
>
> ```sh
> Error: reinterpreting cast from
> `const(validate_KnownRegex_enum_init_type)*` to
> `const(upb_MiniTable_Enum)*` is not supported in CTFE
> ```
The addresses of items stored in memory are by definition not
constant. This isn't a bug.
More information about the Digitalmars-d-learn
mailing list