public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: gcc@gcc.gnu.org
Subject: Union initialization semantics
Date: Wed, 19 Jun 2024 13:57:03 +0300 (MSK)	[thread overview]
Message-ID: <18671112-7250-d15b-b379-337e40d80317@ispras.ru> (raw)

Hello,

I vaguely remember there was a recent, maybe within last two months, discussion
about semantics of union initialization where sizeof(first member) is less than
sizeof(union). The question was whether it's okay to initialize just that first
member and leave garbage bits in the other, larger, members of the union, like
in this example:

union A {
    char a;
    long : 0;
};

void fn(void *);

void my(void)
{
    union A a = { 0 };
    fn(&a);
}

(except in my example there's no other named member, but I think the example
in that discussion was less contrived)

Perhaps somebody remembers where it was (I'm thinking Bugzilla) and could point
me to it? My attempts to search for it aren't turning anything up so far.

If someone knows what semantics GCC implements, that also would be welcome.

Thank you.
Alexander

             reply	other threads:[~2024-06-19 10:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19 10:57 Alexander Monakov [this message]
2024-06-19 12:59 ` Jonathan Wakely
2024-06-19 19:02   ` Martin Uecker

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=18671112-7250-d15b-b379-337e40d80317@ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=gcc@gcc.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).