It is permitted to have a lot of macros. Why does that trouble you?
A macro like
#define STRUCT_KFIFO_PTR(type) \
struct __STRUCT_KFIFO_PTR(type, 0, type)
is not a function-like macro.
A macro like
#define kfifo_initialized(fifo) ((fifo)->kfifo.mask)
could be also used on the left side of some assignment (even if you probably should not do that). And it is shorter to write than the corresponding inline
function
static inline unsigned kfifo_initialezed_f(struct __kfifo *fifo) {
return fifo->kfifo.mask;
}
and more importantly the macro kfifo_initialized
would work with several different declarations of its fifo
actual argument (it is "generic" in some limited sense).
A macro like
#define __STRUCT_KFIFO(type, size, recsize, ptrtype) \
{ \
__STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
type buf[((size < 2) || (size & (size - 1))) ? -1 : size]; \
}
would expand to a declaration equivalent to an array buf[-1]
if given a size
of 3
and that would make the compiler yell. (The recent C++2011 standard also has static_assert
for such purposes).
So I don't understand why you are surprised. The C preprocessor is useful (IMHO it is even not powerful enough). Why avoid using it?
This is free software; if you don't like that source file, you could work to improve it (and that would take time) to propose a better solution. I do like the current one.