Need Advice: Union or Variant?
jwatson-CO-edu
real.name at colorado.edu
Sat Nov 19 03:38:26 UTC 2022
On Thursday, 17 November 2022 at 22:49:37 UTC, H. S. Teoh wrote:
> Just create a nested anonymous struct, like this:
>
> struct Atom {
> F_Type kind;
> union { // anonymous union
> struct {
> Atom* car; // ----------------- Left `Atom` Pointer
> Atom* cdr; // ----------------- Right `Atom` Pointer
> }
> struct {
> double num; // ----------------- Number value
> string str; // ----------------- String value, D-string
> underlies
> }
> bool bul; // ----------------- Boolean value
> }
> F_Error err = F_Error.NOVALUE; // Error code
> }
>
>
> T
Thank you, something similar to what you suggested reduced the
atom size from 72 bytes to 40.
More information about the Digitalmars-d-learn
mailing list