Question

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?

Was it helpful?

Solution

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

OTHER TIPS

You don't only see parenthesis around their names, you see more, for example LIB_(strcmp). Somewhere in your source, LIB_ is defined as a macro; to understand what's happening you need to read what that macro does.

This is generally done to either modify the names of functions in a library in some standardized naming convention, or add attributes to the function (in a compiler specific way).

I believe LIB_ is a macro defined somewhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top