CTFE limitation on reinterpreting cast

Walter Bright newshound2 at digitalmars.com
Thu Oct 1 06:44:55 UTC 2026


On 9/29/2026 8:38 PM, Rambutan wrote:
> Thank you for confirming what I speculated earlier in this thread when I said 
> this is dangerous and so may be the motive for banning reinterpreting casts in 
> CTFE.
> 
> However I also pointed out that there is no problem with such a cast if the new 
> pointer is never indirected in any way at compile time. So a better rule would 
> be to ban any kind of indirection using the result of a reinterpreting cast, and 
> NOT to ban the cast itself.
> 
> That way placing cast pointers to globals in global struct initializers would be 
> legal, as it is in C.

I understand your point, and it has merit. But I am apprehensive in allowing 
CTFE to make bad pointers, even if they are not dereferenced. Perhaps consider a 
union instead?



More information about the Digitalmars-d mailing list