www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - can not take const struct member address at CTFE , is this a bug?

reply test123 <test123 gmail.com> writes:
```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
```
Sep 13 2022
parent reply Ruby The Roobster <rubytheroobster yandex.com> writes:
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.
Sep 13 2022
parent reply test123 <test123 gmail.com> writes:
On Wednesday, 14 September 2022 at 00:40:38 UTC, Ruby The 
Roobster wrote:
 The addresses of items stored in memory are by definition not 
 constant.  This isn't a bug.
If so why this can work ? ```d struct c { uint a, b;} __gshared const c d = { 3, 4}; __gshared const e = & d; ``` the `e` can get address of `d`, then it should be to get address of `d.a`
Sep 13 2022
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 9/14/22 12:53 AM, test123 wrote:
 On Wednesday, 14 September 2022 at 00:40:38 UTC, Ruby The Roobster wrote:
 The addresses of items stored in memory are by definition not 
 constant.  This isn't a bug.
If so why this can work ? ```d struct c { uint a, b;} __gshared const c d = { 3, 4}; __gshared const e = & d; ``` the `e` can get address of `d`, then it should be to get address of `d.a`
Yes, this looks like a bug. Please report if not reported already. -Steve
Sep 14 2022
parent reply test123 <test123 gmail.com> writes:
On Wednesday, 14 September 2022 at 14:41:38 UTC, Steven 
Schveighoffer wrote:
 On 9/14/22 12:53 AM, test123 wrote:
 On Wednesday, 14 September 2022 at 00:40:38 UTC, Ruby The 
 Roobster wrote:
 The addresses of items stored in memory are by definition not 
 constant.  This isn't a bug.
If so why this can work ? ```d struct c { uint a, b;} __gshared const c d = { 3, 4}; __gshared const e = & d; ``` the `e` can get address of `d`, then it should be to get address of `d.a`
Yes, this looks like a bug. Please report if not reported already. -Steve
Thanks for explain. Some how I can not create account for d Bugs, I hope we have use github bugs. Please help me create a bug report if who has free time and bugs account.
Sep 14 2022
parent reply Dennis <dkorpel gmail.com> writes:
On Thursday, 15 September 2022 at 04:13:56 UTC, test123 wrote:
 I hope we have github bugs.
It's being worked on.
 Please help me create a bug report if who has free time and 
 bugs account.
Here you go: https://issues.dlang.org/show_bug.cgi?id=23336
Sep 15 2022
parent test123 <test123 gmail.com> writes:
On Thursday, 15 September 2022 at 11:33:43 UTC, Dennis wrote:
 On Thursday, 15 September 2022 at 04:13:56 UTC, test123 wrote:
 I hope we have github bugs.
It's being worked on.
glad to know we are move into github.
 Please help me create a bug report if who has free time and 
 bugs account.
Here you go: https://issues.dlang.org/show_bug.cgi?id=23336
thanks for the help.
Sep 15 2022