Is it possible to somehow do function overload in C?

I already program at a time in C, procedurally, but a few months ago I started programming object-oriented. In Java, you can do function overloading. Since Java is an object-oriented language that was developed based on the C language, I imagine that somehow it is possible to do function overload, just as I can do in Java, as it is of great use to me.

Author: Maniero, 2018-05-02

2 answers

Yes, it is possible.

  • through macros and complex codes (example )
  • through some external tool
  • creating a name pattern that facilitates
  • Use _Generic() available in c11
  • creating a dynamic system of variables

Has limitations, it gets ugly, I do not recommend, but it is possible.

 3
Author: Maniero, 2020-07-20 12:04:42

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

 2
Author: epx, 2018-05-02 03:30:39