跳过函数调用如果没有定义 [英] Skipping function call if not defined

查看:128
本文介绍了跳过函数调用如果没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包括了不同模块的节目。模块通过函数调用互连。例如。国家呼吁初始化各个模块的初始化函数。它应是可以禁用模块(编译自排除)。最简单的方法是使用preprocessor定义。但是,这会产生code的大量的:

I have a program consisting out of different modules. The modules are interconnected via function calls. E.g. State Init calls the init function of every module. It shall be possible to disable modules (exclude from compilation). The easiest way would be using preprocessor defines. But this generates massive amount of code:

#IF MODULE_XXX_COMPILE
     ret = module_func(...);
#ELSE
     ret = 0;
#ENDIF

我想获得一个宏是这样的:

I would like to get a macro like this:

ret = MOD_COMPILE_CALL(module_func(...));

因此​​,如果宏检查定义为1,如果是它执行其他的功能它跳过执行,并返回0。
问题是,我的编译器是告诉我,它不可能使用 #IF 中的宏。有没有办法解决它?

So the macro checks if the define is 1 if yes it executes the functions else it skips the execution and returns 0. The problem is that my compiler is telling me that its not possible to use #IF in a macro. Is there a way around it?

推荐答案

而不是使用#如果里面的宏,这很可能会无法正常工作,你可以只把它拿出来

Instead of using #if inside your macro, which will probably not work you could just take it out:

#if MODULE_XXX_COMPILE == 1
    #define MOD_COMPILE_CALL(fcall) (fcall)
#else
    #define MOD_COMPILE_CALL(fcall) (0)
#endif

这篇关于跳过函数调用如果没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆