Question : log4c practice

The following appears in category.h

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
/**
 * Return true if the category will log messages with priority @c
 * LOG4C_PRIORITY_DEBUG.
 *
 * @param a_category the log4c_category_t object
 * @returns Whether the category will log.
 **/ 
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_debug_enabled(const log4c_category_t* a_category) 
{	
    return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_DEBUG); 
}
#else
#define log4c_category_is_debug_enabled(a) \
  (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_DEBUG))
#endif


and this seems to make sense, but what of the frequently used

1:
2:
3:
if (log4c_category_is_debug_enabled(a_cat)) {
// Log something at debug level
}


? Does anyone here do something like log_debug(...) such that the if gets inlined too? Surely that would be more convenient than evaluating (explicitly) the if each time

Answer : log4c practice

I guess the idea is to evaluate the category the minimum number of times for efficiency. It makes sense for the if to be evaluated explicitly by the caller and for the boolean to be retained for the relevant scope.
Random Solutions  
 
programming4us programming4us