-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use C11 _Generic instead of void * in public API #13
Comments
This would probably by an improvement. It could even be done without breaking ABI. Another approach that I've considered is to approximate type traits via struct members. The interface would still be partially opaque, but the first members for the structs would be exposed. For example:
Then you could do...
At least, this would be an interesting experiment in interface design. |
Technically speaking using struct aml_handler *handler = ...;
void *obj = handler;
return aml_get_fd(obj); Though probably nobody does this in practice.
This would be better. I can see these potential downsides:
|
I don't mind breaking API as much as ABI. That being said, I've been wanting to redesign the interface for a while anyway based on some observations that I've made:
If/when I do redesign it, I think I'll just do the right thing and duplicate those functions across different types. I did it this way originally because of laziness and a sudden urge to question conventional wisdom. |
I agree with all of the points above. |
I haven't removed the superfluous things from the API, but at least type safety is addressed: #14 |
Very nice, thanks for that! |
The public API allows the same functions to be used on different kinds of objects. This makes it pretty error-prone: it's easy to call a function on an invalid type without any compile-time error (either an aml type not accepted by the function in which case it's a runtime error, or a completely foreign type in which case it's just fireworks). C11
_Generic
could be used to indicate which types are accepted by a function, e.g:(Note that in general I am not a fan of functions accepting multiple types of arguments, and would just recommend duplicating the functions into multiple wrappers.)
The text was updated successfully, but these errors were encountered: