If you're calling this across translation units, the calling convention will come with a performance penalty, but boy have we come full circle since pre-ANSI C required you to pass args as a struct. Much love - wish the language required struct and arg list to be the same thing. You can send a list of em and it'll work with algebraic data types for batching calls. The dream. CPU doesn't play nice though since structs aren't register shaped, but maybe they could be in a future calling convention.
To me, “keyword arguments” means actual language keywords being used as arguments, like “minute” or “hour” in T-SQL’s DATEDIFF, for example: `SELECT DATEDIFF( hour, NOW(), someDateCol )`.
…but I think the author meant “named arguments”, like we have in C#, Swift, and Objective-C.
> I pretty much always prefer using an options struct
This is essentially what Vulkan does; there's a CreateInfo struct for every object creation or command function. And even then they managed to sort of mess it up, because they also have functions and objects suffixed with a '2', and the pNext extension mechanism.
I use this all the time in C (specifically, C99 or later). I first saw it used in anger in `sokol_gfx`, and loved it. `FLECS` does something similar.
C makes it much better than C++ in that the designated initializes can be set in any order --- so I don't need to remember the often-arbitrary order of struct fields for the options struct.
I find it weird that C++ took this great C feature and kneecapped it ...
I did this in my C project 7 years ago, as this is standard in C and gave a lot of readability, in fact more I guess... but a lot of preprocessor code too
10 comments
[ 2.6 ms ] story [ 26.4 ms ] thread…but I think the author meant “named arguments”, like we have in C#, Swift, and Objective-C.
EDIT: Thanks commenter hawkice for fixing my XOR arithmetic!
Comes out cleaner because overriding a default argument doesn’t force you to also do all the positional arguments in front of it.
Designated initializers make it look really nice imo. I feel like the brackets are no big deal.
Python has sort of the opposite when you need to use *kwargs.
This is essentially what Vulkan does; there's a CreateInfo struct for every object creation or command function. And even then they managed to sort of mess it up, because they also have functions and objects suffixed with a '2', and the pNext extension mechanism.
C makes it much better than C++ in that the designated initializes can be set in any order --- so I don't need to remember the often-arbitrary order of struct fields for the options struct.
I find it weird that C++ took this great C feature and kneecapped it ...
0. https://youtu.be/Grveezn0zhU