all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniel Colascione <dancol@dancol.org>
To: Emacs developers <emacs-devel@gnu.org>
Subject: Why named structs and unions? C11 supports anonymous structs and unions
Date: Sun, 11 Feb 2018 19:14:59 -0800	[thread overview]
Message-ID: <53a9ab33-cdd5-99b3-aeef-f52776a5bf8d@dancol.org> (raw)

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	other threads:[~2018-02-12  3:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12  3:14 Daniel Colascione [this message]
2018-02-12  3:56 ` Why named structs and unions? C11 supports anonymous structs and unions 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53a9ab33-cdd5-99b3-aeef-f52776a5bf8d@dancol.org \
    --to=dancol@dancol.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.