Null references redux + Cyclone
Nick Sabalausky
a at a.a
Mon Sep 28 15:12:08 PDT 2009
"bearophile" <bearophileHUGS at lycos.com> wrote in message
news:h9qo0l$750$1 at digitalmars.com...
>
> But beside normal C unions that I don't want to remove from C, it can be
> also useful to have safe automatic tagged unions of Cyclone. They are
> safer and give just a little less performance compared to C unions. In D
> they may be denoted with "record" or "tunion" or just "safe union" to save
> keywords. They always contain an invisible tag (that can be read with a
> special built-in union method, like Unioname.tagcheck). Such "safe unions"
> may even become the only ones allowed in SafeD modules!
>
> The following is from Cyclone docs:
> <<
> The C Standard says that if you read out any member of a union other than
> the last one written, the result is undefined.
> To avoid this problem, Cyclone provides a built-in form of tagged union
> and always ensures that the tag is correlated with the last member written
> in the union. In particular, whenever a tagged union member is updated,
> the compiler inserts code to update the tag associated with the union.
> Whenever a member is read, the tag is consulted to ensure that the member
> was the last one written. If not, an exception is thrown.
>
Sounds like a variant to me, but just without automatic conversion. Or am I
misunderstanding?
More information about the Digitalmars-d
mailing list