Deutsch   English   Français   Italiano  
<velin3$1m8c1$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!npeer.as286.net!npeer-ng0.as286.net!3.eu.feeder.erje.net!feeder.erje.net!news.in-chemnitz.de!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: c initialization algorithm
Date: Tue, 15 Oct 2024 08:12:35 -0300
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <velin3$1m8c1$1@dont-email.me>
References: <vehee7$r8ri$1@dont-email.me> <20241013163050.897@kylheku.com>
 <86cyk3xoqw.fsf@linuxsc.com> <veiuf0$15s23$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 15 Oct 2024 13:12:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="77a1174b06f1d1508764a1a6759a5811";
	logging-data="1778049"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19mdShgq64nVEiHJZ6vwSe4YMXjZj5r8X0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:qrzJIQA0g/dDmksS7XoAU78SymM=
Content-Language: en-US
In-Reply-To: <veiuf0$15s23$1@dont-email.me>
Bytes: 2437

On 14/10/2024 08:14, Thiago Adams wrote:
> On 14/10/2024 02:00, Tim Rentsch wrote:
>> Kaz Kylheku <643-408-1753@kylheku.com> writes:
>>
>>> On 2024-10-13, Thiago Adams <thiago.adams@gmail.com> wrote:
>>>
>>>> The algorithm for C initialization as described in the standard
>>>> and implemented in gcc allow this.
>>>>
>>>> struct X{
>>>>       int a,b,c;
>>>> };
>>>>
>>>> int main()
>>>> {
>>>>       struct X x = {.a=1,2,3,.a=1, 2, 3};
>>>> }
>>>>
>>>> https://godbolt.org/z/7naedbEM6
>>>>
>>>> Basically, when a designed initializer is found the "cursor" goes
>>>> to that member and the following members are initialized in
>>>> order.
>>>
>>>   I do not suspect that therw is an observable order.  I.e. as
>>>   in a required order considered observable behavior.
>>
>> Have you checked to C standard to see what it says about that?

I'm not only interested in this part, but since it raised some doubts, I 
decided to do some checks

#include <stdio.h>

struct X {
     int i;
};

int f() {
     printf("f");
     return 1;
}

int main() {
     struct X x = {.i = f(), .i = f() };
}

https://godbolt.org/z/rf984cGMM

There is a warning in this sample and f is called just once.