c - Why is kfifo.h so full of #define statements -


this question has answer here:

kfifo.h made entirely of #define. why that? why have not declared functions in h file "normally" done.

[edit]

it seems question interpreted questioning of implementation rather ment ask, why implementation better, learning standpoint. anyway, since didn't know looking @ "function-like macros" voting close since it's obviosly duplicate.

it permitted have lot of macros. why trouble you?

a macro

 #define struct_kfifo_ptr(type) \    struct __struct_kfifo_ptr(type, 0, type) 

is not function-like macro.

a macro

 #define kfifo_initialized(fifo) ((fifo)->kfifo.mask) 

could used on left side of assignment (even if should not that). , shorter write corresponding inline function

 static inline unsigned kfifo_initialezed_f(struct __kfifo *fifo) {     return fifo->kfifo.mask;  } 

and more importantly macro kfifo_initialized work several different declarations of fifo actual argument (it "generic" in 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 declaration equivalent array buf[-1] if given size of 3 , make compiler yell. (the recent c++2011 standard has static_assert such purposes).

so don't understand why surprised. c preprocessor useful (imho not powerful enough). why avoid using it?

this free software; if don't source file, work improve it (and take time) propose better solution. current one.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -