Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #395809
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: GCC bug |
| Date | Sun, 14 Dec 2025 22:38:34 -0800 |
| Organization | A noiseless patient Spider |
| Lines | 36 |
| Message-ID | <86o6o0uu51.fsf@linuxsc.com> (permalink) |
| References | <109rvpl$1pdsj$1@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Date | Mon, 15 Dec 2025 06:38:39 +0000 (UTC) |
| Injection-Info | dont-email.me; posting-host="3b66f75cc16331490dd39d06d7ef9603"; logging-data="1779032"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jQveNbO4OxxCzDkCaKwBywoNvnpxuyY8=" |
| User-Agent | Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) |
| Cancel-Lock | sha1:Ax5eEsKvJg6PFw/qXaL6EWqLL+c= sha1:9N7Me/qomb33VX6R+Co8qQ1UHhg= |
| Xref | csiph.com comp.lang.c:395809 |
Show key headers only | View raw
Andrey Tarasevich <noone@noone.net> writes:
> An attempt to use designated initializers to explicitly re-initialize
> a sub-member `y` of a struct member `b.a`
>
> #include <stdio.h>
>
> struct A { int x, y; };
> struct B { struct A a; };
>
> int main(void)
> {
> struct A ia = { 1, 2 };
> struct B b = { .a = ia, .a.y = 42 };
> printf("%d %d\n", b.a.x, b.a.y);
> }
>
> GCC outputs:
>
> 0 42
>
> I.e. it does initialize `b.a.y` with `42`, but for some reason also
> produces zero in `b.a.x`. Meanwhile, Clang, MSVC output
>
> 1 42
>
> as expected.
>
> The funny part is that this exact functionality is actually directly
> illustrated by the standard in "6.7.11 Initialization" example 12.
>
> Is it just a bug or is there some defiant reasoning (e.g. "we know
> better") for GCC's behavior?
Given the example that is shown in the C standard, it seems clear
that what gcc does is wrong, so may be called a bug.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar
GCC bug Andrey Tarasevich <noone@noone.net> - 2025-09-10 06:51 -0700
Re: GCC bug Michael S <already5chosen@yahoo.com> - 2025-09-10 17:45 +0300
Re: GCC bug Andrey Tarasevich <noone@noone.net> - 2025-09-10 21:15 -0700
Re: GCC bug Michael S <already5chosen@yahoo.com> - 2025-09-11 11:57 +0300
Re: GCC bug Andrey Tarasevich <noone@noone.net> - 2025-09-11 05:11 -0700
Re: GCC bug Damien Wyart <damien.wyart@free.fr> - 2025-09-11 09:36 +0200
Re: GCC bug Andrey Tarasevich <noone@noone.net> - 2025-09-11 05:28 -0700
Re: GCC bug Andrey Tarasevich <noone@noone.net> - 2025-09-11 19:04 -0700
Re: GCC bug Kaz Kylheku <643-408-1753@kylheku.com> - 2025-09-12 03:45 +0000
Re: GCC bug Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-12-14 22:38 -0800
csiph-web