emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why named structs and unions? C11 supports anonymous structs and unions


From: Daniel Colascione
Subject: Why named structs and unions? C11 supports anonymous structs and unions
Date: Sun, 11 Feb 2018 19:14:59 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

Recently, we changed structs from being declared plainly to being structs-of-a-union-containing-a-struct-and-a-dummy-aligner. I understand the reasoning for this change, but not the way it's done. It's uglified the code. Instead of XCONS(c)->car, we now write XCONS(c)->u.s.car. We don't have to though.

Instead of:

struct foo {
  union {
    struct {
      int stuff1;
      int stuff2;
    } s;
    char alignas(GCALIGNMENT) gcaligned;
  } u;
};

we can write this:

struct foo {
  union {
    struct {
      int stuff1;
      int stuff2;
    };
    char alignas(GCALIGNMENT) gcaligned;
  };
};

Now we get all the alignment benefits of alignas, but without the ugly "u.s." stuff. C11 allows these anonymous composite members, and AFAICT, so does every compiler that anyone cares about anymore. So why not use them?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]