Created
September 7, 2018 17:49
-
-
Save arkku/adc8bc579ea9fcd98c29d91d1ef6c5d5 to your computer and use it in GitHub Desktop.
Named arguments in C (not necessarily recommended)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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