C function decorators (wrappers) at compile time -
I am trying to change the behavior of some functions in C with the help of preprocessor; And optional parameters that can be turned on or off ...
The basic form of optional parameters is simple:
#ifdef OPT_PARAM #define my_func ( A, b, opt) _my_func (a, b, opt) #else #define my_func (a, b, opt) _my_func (a, b) #endif / * The rest of the codes always call "my_func" with all the parameters And not the underlined version ... * / #ifdef OPT_PARAM Strange _my_func (int one, int b, int opt) #else void _my_func (int one, int b) #endif {/ * ... more #ifdefs Uses * />>
The function is conditional The pattern is the same for wrapping the way, but the problem is that starting to add underscores (one extra for each nesting level, it can be a different function or just do not wrap it up to the #define next level is).
So, is there any idea about reducing code complexity here?
PS I am ready to use Python ... but it is for a driver: - (
Looks like you want to use default arguments or some things that are not available in C. This is a bad idea, why not handle things in another C fashion, where If you do not want to specify any argument, then you only have to tap or -1 (standard).
zero function (int a, int b, int c) {if (c! = - 1) {// something}} Hnkshn (a, b, -) 1); Function (A, B, C);
Comments
Post a Comment