Deutsch English Français Italiano |
<vehee7$r8ri$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!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: c initialization algorithm Date: Sun, 13 Oct 2024 18:35:03 -0300 Organization: A noiseless patient Spider Lines: 25 Message-ID: <vehee7$r8ri$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 13 Oct 2024 23:35:04 +0200 (CEST) Injection-Info: dont-email.me; posting-host="b9d5dd9688ffdaba1d061cdfa3066275"; logging-data="893810"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fismwdnGweXoWCW8DZPKRqkAVrB/yLTE=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:0yv8Fvd0cyQK7f3d8jTQaDaqDzM= Content-Language: en-GB Bytes: 1382 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. struct X{ int a,b,c; }; int main() { struct X x = {.a=1,2,3,.a=1, 2, 3, .a=1, 4, 5}; }