3 ms·
In C99 you can sort-of get named optional parameters via designated-initialization, e.g. if a function takes a a struct "person_t" by value you can write: my_f
by flohofwoe 7y ago
In C99 you can sort-of get named optional parameters via designated-initialization, e.g. if a function takes a a struct "person_t" by value you can write:
my_func((person_t){ .name = "John Doe", .age = 33 });
...by-pointer also works:
my_func(&(person_t){ .name = "John Doe", .age = 33 });
Any struct items which are not assigned a value will be zero-initialized (I wish it would be possible to define default-values in the struct declaration though).
I question the value of bringing OO principles into plain C though ;)