CTFE limitation on reinterpreting cast

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Thu Oct 1 07:15:22 UTC 2026


On 01/10/2026 7:44 PM, Walter Bright wrote:
> 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?

Ya know, C has rules for how structs can be merged.

Perhaps that is a good place to look at.



More information about the Digitalmars-d mailing list