r/C_Programming • • 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

46 comments sorted by

View all comments

Show parent comment

1

u/dstroy0 Aug 29 '26

The OPs intent is explicit, using macros removes some of that. Understand?

1

u/torsten_dev Aug 29 '26

Sure, tell that to OP, doesn't have anything to do with what I said though.

-3

u/dstroy0 Aug 29 '26

The new standard is a macro. That you suggested. Understand?

1

u/torsten_dev Aug 29 '26

It's not though. It's a new type. Depending on the name chosen and commitee direction there may additionally be a header which defines a macro like any_func but that's how new types and keywords are introduced that can clash with existing code.

0

u/dstroy0 Aug 29 '26

You’re missing the point entirely. _Atomic is not the same thing as <stdatomic>.

2

u/torsten_dev Aug 29 '26

I wrote _Any_func though.

3

u/dstroy0 Aug 29 '26

The point is, they removed explicit intent and replaced it with your example. Which is what I have been saying that you've been missing this entire time. Understand now????

3

u/torsten_dev Aug 29 '26

No. I don't understand. This would be a literal

#define any_func _Any_func

convenience macro. It's not a function like macro. It can't do something sneaky.

2

u/dstroy0 Aug 29 '26
#include <stddef.h>
#define ptmethod(pt, ret_type, identifier) \     
    (*(ret_type (**)(typeof(pt), ...)) padd(pt, identifier, ptfunction, NULL, NULL))

#define ptapply(pt, ret_type, identifier, ...) \     
    ((ret_type (*)(typeof(pt), ...)) pget(pt, identifier))(pt __VA_OPT__(,) __VA_ARGS__)

1

u/glasket_ Aug 30 '26

It's wild that you're getting downvoted while that complete nonsense is getting upvoted, especially when nothing discussed actually involves macros. If "explicit intent" is being removed you'd think they could explain what that "explicit intent" actually is in this case and how the alternatives don't provide it.

2

u/torsten_dev Aug 30 '26

Finally understood what he was getting at. _Any_func erases the return type, which OP's macros don't. Thus using _Any_func would erase part of the intent of OP's macros, because OP's intent wasn't to erase the return type.

At least I think that's it. His comments were very confusing.

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.

→ More replies