LangProc / langproc-2018-cw

5 stars 4 forks source link

Function Overloads #36

Closed QFSW closed 5 years ago

QFSW commented 5 years ago

Do we need to support overloading functions? Such as

int multiply(int a, int b) { return a * b; }
double multiply(double a, double b) { return a * b; }

In a similar vein, what about default parameters?

ymherklotz commented 5 years ago

No, both are not valid C90.

$ gcc -std=c90 -ansi -pedantic -o main main.c                                                                                                                                                                                           
main.c:2:8: error: conflicting types for ‘multiply’
QFSW commented 5 years ago

Thanks, so functions must be completely unique by name in C90?

ymherklotz commented 5 years ago

Yes, function overloading does not exist in C, and only exists in C++. For example: https://stackoverflow.com/questions/479207/how-to-achieve-function-overloading-in-c/25026358#25026358