4 ms·
> C++20 does have C11's designated initialization now, which helps in some cases, but that was a pain for a long time. C++ designated initializers are slightly
by aw1621107 1y ago
> C++20 does have C11's designated initialization now, which helps in some cases, but that was a pain for a long time.
C++ designated initializers are slightly different in that the initialization order must match the declared member order. That is not required in C.
- o11c 1y agoIt also completely negates their utility, even though the exact "problem" they always bring up is already solved when you use normal constructors.
- jcelerier 1y agoNot sure I understand, since they're available in c++ designated initializes are one of the features I use most, to the point of making custom structs to pass the arguments if a type cannot be changed to be an aggregate. It makes a huge positive difference in readability and has helped me solve many subtle bugs ; and not initializing things in order will throw a warning so you catch it immediately in your ide
- o11c 1y agoThe problem is that there are a lot of APIs (even system and system-ish ones) that don't want to specify the order of their fields (or outright differ between platforms). Or that can't use a meaningful order due to ABI compatibility, yet the caller wants to pass fields in a meaningful order.
- jcelerier 1y agoplatform APIs like this are likely much less less than 1% of the things I call in my codebases. The few files i have open right now have absolutely no such call.