I work with pthreads and I want to use this code:
if(pthread_mutex_lock(&lock)){
cout<<"error"<<endl;
return ERROR;
}
my question is should I do it with #define or should I do it with inline function:
inline void func() {
if(pthread_mutex_lock(&lock)){
cout<<"error"<<endl;
return ERROR;
}
}
Should the function be static? such as:
static inline void func()
You shouldn’t do anything with macros if you can help it (and here, you can help it).
If your function lives and is used solely in a cpp it should be in an unnamed namespace…
If it’s declared in a header and meant to be used from many other cpps it should not be static or in an unnamed namespace.