Earlier quoted context omitted.
> I really don’t understand why they are not allowed. I don't, either. Such were in D from 2000 or so. I also don't understand why `class` in C++ sits in the tag name space. I wrote Bjarne in the 1980s asking him to remove it from the tag name space, as the tag name space is an abomination. He replied that there was too much water under that bridge. D doesn't have the tag name space, and in 20 years not a single pers…
The only explanation I saw was that C++ standards guys were horrified by the idea of unpredictable side effects as a result of initialization of a struct. I think C++ though is adding them. What I'd like in c is designated function parameters. // these the same bar(.a = 10, .b = 12); bar(.b = 12, .a = 10);
struct bar_arguments {
int a, b;
};
int bar(struct bar_arguments args) { return 2*args.a + args.b;}
#define bar(...) bar((struct bar_arguments) {__VA_ARGS__})
// usage (will print 32 three times)
printf("%d\n", bar(10, 12));
printf("%d\n", bar(.a = 10, .b = 12));
printf("%d\n", bar(.b = 12, .a = 10));
The main drawback is that all parameters are now optional: it will not complain if you forget to assign all parameters, it will silently set them to 0 :-/ printf("%d\n", bar(10));
printf("%d\n", bar(.a = 10));
printf("%d\n", bar(.b = 12));
will print 20, 20 and 12.You can change those "default values", but then calling the function with regular positional parameters is impaired :-/