Last active
December 18, 2021 05:58
-
-
Save opsJson/8e4637b2da58c9e22ccc1dd7b23d47d1 to your computer and use it in GitHub Desktop.
Python keyword arguments in C.
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> | |
| //create your arguments list. | |
| struct args { | |
| char *name; | |
| int x; | |
| int y; | |
| int width; | |
| int height; | |
| }; | |
| //create a function that receives a pointer to your arguments list. | |
| void foo(struct args *a) { | |
| printf("%s %i %i %i %i\n", a->name, a->x, a->y, a->width, a->height); | |
| } | |
| //create a macro that converts foo(...) to foo(pointer of your arguments list) | |
| #define foo(...) foo(&(struct args) {__VA_ARGS__}) | |
| int main() { | |
| foo(.x = 10, .y = 20, .name = "Hello, world!\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment