3 ms·
This is kind of neat to get named arguments in C as well. Instead of calling: foo_init(1, 'a', 1.0); You can write: foo_init(.arg1=1, .arg3=1.0, .ar
by 0xABADC0DA 15y ago
This is kind of neat to get named arguments in C as well.
Instead of calling:
foo_init(1, 'a', 1.0);
You can write:
foo_init(.arg1=1, .arg3=1.0, .arg2='a');
foo_init(.arg3='c');
// etc
edit: didn't see this in the blog comments, wasn't trying to steal credit ;-P
- deleted 15y ago[deleted]
- LefterisJP 15y agoHello, I am the author of the linked blog. Your idea is indeed very neat too. Refer to the comment made in the blog by Jens Gustedt. It has lots of potential imo
- cygx 15y agoThe combination of compound literals and variadic macros is indeed pretty neat. It can also be used to implement Java-style variadic functions (ie when the variadic parameters have a single type): #define sum(...) \ sum_(sizeof ((int []){ __VA_ARGS__ }) / sizeof (int), (int []){ __VA_ARGS__ }) int sum_(size_t count, int values[]) { int s = 0; while(count--) s += values[count]; return s; } You'd call the macro as int s = sum(1, -32, 5);
- LefterisJP 15y agonice idea!