CTFE Assignment to anonymous union shows unexpected behavior

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Apr 23 00:55:50 UTC 2021


On Thu, Apr 22, 2021 at 11:44:51PM +0000, Rekel via Digitalmars-d-learn wrote:
> On Thursday, 22 April 2021 at 23:41:33 UTC, H. S. Teoh wrote:
> > On Thu, Apr 22, 2021 at 10:47:17PM +0000, Rekel via Digitalmars-d-learn
> > wrote:
> > > I'm not sure why this is happening, but after simplifying my code
> > > I traced it back to what the title may suggest.
> > 
> > Keep in mind that CTFE does not support reinterpretation via unions,
> > i.e., reading values from a different field in a union than was
> > assigned. If you assign field A to a union, then you cannot read field B
> > from that union in CTFE. You can only do this at runtime, not in CTFE.
[...]
> I'm not sure what you mean,
> do you mean if i were to read the field during CTFE, or even if i read
> the field during runtime after initializing it using CTFE?

If you read the field during CTFE.  I've never tested initializing a
union in CTFE then reading it at runtime, though. Not sure exactly what
would happen in that case.


T

-- 
Recently, our IT department hired a bug-fix engineer. He used to work for Volkswagen.


More information about the Digitalmars-d-learn mailing list