Is it possible somehow to overload functions in C?

Asked

Viewed 607 times

2

I’m already programming in C, in a procedural way, but a few months ago I started programming oriented to objects. In Java, it is possible to overload functions. Since Java is an object-oriented language that was developed based on the C language, I imagine that it is somehow possible to overload functions, as well as I can do in Java, as it is very useful to me.

2 answers

3


Yes, it is possible.

  • through macros and complex codes (example)
  • through some external tool
  • creating a name pattern that makes it easy
  • use _Generic() available in C11
  • creating a dynamic system of variables

It has limitations, it gets ugly, I don’t recommend it, but it’s possible.

  • I imagined, because it is a procedural language. I will start my studies in C++ then. I already use cplusplus Docs anyway. But if it is limited, it is not worth saying that it has how. Either it can, or it cannot.

2

In C, no. In C++, yes. You can develop in "C" and compile as C++ just to use the C++ resources that interest you, in the case of function overload.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.