r/C_Programming • u/Future_Pace_5290 • Aug 29 '26
Is the empty parenthesis function (() instead of (void)) prototype removed in the new standard?
My OOP library relies on it for its unspecified arguments behavior.
For example:
#define ptmethod(pt, ret_type, identifier) \
(*((ret_type (**)()) padd(pt, identifier, ptfunction, NULL, NULL)))
#define ptapply(pt, ret_type, identifier, ...) \
((ret_type (*)()) pget(pt, identifier))(pt __VA_OPT__(,) __VA_ARGS__)You could add a method to an object with:
void drive_Car(prototype *Car, double speed, double x_direction, double y_direction);
ptmethod(Car, void, "drive") = drive_Car;
and call it with
ptapply(Car, void, "drive", 1.3, 0.1, 5.0)
How do I do this in the new standard?
13
Upvotes
View all comments
Show parent comment
0
u/dstroy0 Aug 30 '26
It’s wild that there are two of you. Look at the replacement that I wrote that preserves intent. Don’t get hung up on “it’s not a macro” yes it is, the definition of a macro is a representation that gets replaced in situ which is exactly what this is, it’s semantically different from a “literal” macro in name only. Your understanding of the language is not my problem. I also proved that you can cast from and to any function it’s guaranteed to not lose information by the language.