Is there a way to use named arguments in C function?
Something like function with prototype void foo(int a, int b, int c);
and I want to call it with foo(a=2, c=3, b=1); [replaced the order of b & c and used their names to distinguish]
Motivation: I want a more Pythonic C, where I can easily manipulate my function arguments without mixing them by mistake
Kinda, sorta, with a compound literal and designated initializers:
typedef struct foo_args {
  int a;
  int b;
  int c;
} foo_args;
// Later
foo(&(foo_args) {
  .a = 2,
  .c = 3,
  .b = 1
});
But I honestly wouldn't bother. It requires you to bend the function definition to accept a pointer, and makes calling it cumbersome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With