Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function naming in C: parentheses in function names

I was reading a source code when I saw functions with parentheses in their names:

extern int LIB_(strcmp) ( const char* s1, const char* s2 );
extern char LIB_(tolower) ( char c );

What is that?

I am confused because I could call the functions like this: char c = LIB_(tolower)('A');

Isn't it true that in C, parentheses are used to separate function names from parameters and to do type casting?

like image 945
Reza Avatar asked Dec 25 '22 13:12

Reza


1 Answers

This is indeed confusing. LIB_(x) is a macro defined somewhere, which evaluates to the real name of the function.

So the function's name is not actually LIB_(strcmp) but the result of the LIB_(x) macro. Most likely, LIB_(x) is intended to prepend a library name/identifier onto the beginning of the function and is defined like this:

/* prepend libname_ onto the name of the function (x) */
#define LIB_(x) libname_ ## x
like image 112
TypeIA Avatar answered Jan 08 '23 12:01

TypeIA