Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC: Allow overloaded functions in C99

I write code in C99 and compile via GCC. I would like to use function overloading for stylistic reasons (otherwise I would have to do name mangling by myself).

I have read Is there a reason that C99 doesn't support function overloading? however, I still wonder whether it can be enabled in GCC.

Can you help me at this point?

like image 374
shuhalo Avatar asked Dec 01 '22 23:12

shuhalo


1 Answers

No, there is no function overloading in C99, not even in silly GCC extensions. C11 adds _Generic, but even then you still have to mangle names yourself.

void foo_int(int x);
void foo_double(double x);

#define foo(arg) _Generic((arg), int: foo_int, double: foo_double)(arg)

Whether that's better or worse, well. It's C.

like image 91
Cat Plus Plus Avatar answered Dec 24 '22 00:12

Cat Plus Plus