My library contains a function that is used both internally and externally. The function is so small that I want the compiler to try to inline the function when calling internal. Since the function uses information of an incomplete type, external calls cannot be embedded. Therefore, my module should also always contain a copy of the function with external communication.
I think I found the following solution, but would like your advice:
struct stack; extern bool stack_isempty(struct stack *s); #include "stack.h" struct stack { [...]; int size; }; inline bool stack_isempty(struct stack *s) { return s->size == 0; }
Usually I use inline in another way or just put the static inline function in the header file. But, as explained, this is not possible here.
Does this approach get the desired results? Does anyone see flaws in this approach (does it carry the C99)?
schot source share