Search code examples
ccompiler-constructionstandard-library

How does a C runtime library provided by a compiler say gcc alllows different function arguments & return types- float,double,long double?


When i see man sqrt on Linux, I see 3 prototypes of the function -

double sqrt(double x);    
float sqrtf(float x);    
long double sqrtl(long double x);

If compiler/library is written in C++, I understand it might be using function overloading.

If the compiler library that provides this is written in C, How does the compiler(gcc) implement this kind of thing, which is like function overloading which C does not support? (Or is it that some later standard of C like C99 does support something like this?)

What programming language is gcc implemented in?


Solution

  • The function names are simply chosen differently - plain sqrt for double and its friends sqrtf and sqrtl for floats and long doubles. It looks like overloading, but it isn't, because the function names are different.