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

4

u/dstroy0 Aug 29 '26

“They” really do like replacing explicit intent with _Generic like macros. I get the counter argument that it makes the compiler output way more predictable, but can’t we preserve the intent along with it? Doesn’t seem like a difficult problem until you start considering infinite use cases, then macro the funnel starts to be very attractive to compiler developers as an output homogeneity enforcement method.

1

u/torsten_dev Aug 29 '26 edited Sep 03 '26

What?

Can't tell if this is just plain off topic, not a reply to me, and or some schizoposting. You okay?

Edit: Finally parsed his meaning. _Any_func would erase the return type as well as the argument types, OP only asked for erased argument types...

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.

→ More replies