CTFE limitation on reinterpreting cast
Rambutan
s56l6zk0w at mozmail.com
Mon Sep 28 22:50:21 UTC 2026
Here's a tiny version of something I ran into working on a
project with both C and D source, while moving into D a C global
array of structs that was initialized in place.
```
struct B {}
struct C {}
__gshared B Bobj;
auto ptr = cast(C*)&Bobj;
void main() {}
```
Without the cast the initializer `&Bobj` is fine, but with it
this does not compile.
```
$ gdc ctfecast.d
ctfecast.d:6:20: error: reinterpreting cast from 'B*' to 'C*' is
not supported in CTFE
6 | auto ptr = cast(C*)&Bobj;
| ^
```
Why? What can you tell me about this? Is there a workaround? Can
you point me at connected documentation?
Any information about this will be gratefully received.
R.
More information about the Digitalmars-d
mailing list