4 ms·
Address white_house{ .street = "1600 Pennsylvania Avenue NW", .city = "Washington", .state = "District of Columbia", .zip = 20500, }; For me
by p0w3n3d 5mo ago
Address white_house{
.street = "1600 Pennsylvania Avenue NW",
.city = "Washington",
.state = "District of Columbia",
.zip = 20500,
};
For me this is the most important initialization in C that helps with clarity so much, I used mostly structs to have function parameters intialized like this
However C++ had at time no default initialization for unmentioned fields, so in 2017 I had to remove it when converting the code to C++
- einpoklum 5mo agoDesignated initializers were unofficially supported by GCC (and clang IIANM) since around when C++11 was supported. See: https://godbolt.org/z/3aKaa7dnM https://godbolt.org/z/3aKaa7dnM only if you specifically ask to get an error, would you actually get it.
- deleted 5mo ago[deleted]
- 1718627440 5mo agoYeah you can even create linked lists of static data that way, as you can very well just take the pointer of an object here.