all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Why named structs and unions? C11 supports anonymous structs and unions
@ 2018-02-12  3:14 Daniel Colascione
  2018-02-12  3:56 ` Paul Eggert
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Colascione @ 2018-02-12  3:14 UTC (permalink / raw
  To: Emacs developers

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?



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-02-12 22:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-12  3:14 Why named structs and unions? C11 supports anonymous structs and unions Daniel Colascione
2018-02-12  3:56 ` Paul Eggert
2018-02-12  4:09   ` Daniel Colascione
2018-02-12  7:28     ` Paul Eggert
2018-02-12 20:22       ` Daniel Colascione
2018-02-12 20:37         ` Paul Eggert
2018-02-12 22:18     ` Richard Stallman
2018-02-12 22:18     ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.