i have ended putting many little small inline function in a header file which i include in many compilation units, the code is correctly inlined by the compiler and the program works like a charm.
but now the header file is something very unusual (for being a header file), to make it more readable i thought to do something like this:
#ifndef MY_HEADER_H
#define MU_HEADER_H
static inline
void my_fnct (my_param a);
#include "my_header.inline.c"
#endif
and the file my_header.inline.c
will be like:
static inline
void my_fnct (my_param a)
{
// .. my code ..
}
then, when i want these functions i just include the header file.
my question is: there is a better way to accomplish this without filling a header file with too much code? or i can do this and expect other developers to understand this code without problems?
No you cannot. However, you might use the Link Time optimization feature of GCC (then some calls might be inlined, even if the function is not declared inline
and not available in headers for every compilation unit), e.g. compile and link with gcc -flto
(this requires a recent GCC compiler, e.g. 4.6 at least and slows down the build time).
A practice that I don't personally like is to extract inline functions into a separate file with the .inl extension. This is just convention and you can name the file anything you like. I have an IDE that folds code so I can just hide the stuff I don't want to see rather than have a separate file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With