Skip to content

Instantly share code, notes, and snippets.

@arkku
Created September 7, 2018 17:49
Show Gist options
  • Select an option

  • Save arkku/adc8bc579ea9fcd98c29d91d1ef6c5d5 to your computer and use it in GitHub Desktop.

Select an option

Save arkku/adc8bc579ea9fcd98c29d91d1ef6c5d5 to your computer and use it in GitHub Desktop.
Named arguments in C (not necessarily recommended)
#include <stdio.h>
struct foo_args { int bar; char *baz; };
void real_foo(struct foo_args args) {
(void) printf("bar=%d, baz=%s\n", args.bar, args.baz);
}
#define foo(args...) real_foo((struct foo_args) { args })
int main() {
foo(.bar = 1, .baz = "baz");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment