我要弄清楚的是这样的东西(用 C 编写):
What I'm trying to figure out is if something such as this (written in C):
#define FOO 15 #define BAR 23 #define MEH (FOO / BAR)是允许的吗?我希望预处理器替换每个实例
is allowed? I would want the preprocessor to replace every instance of
MEH与
(15 / 23)但我不确定这样做是否可行。当然,如果预处理器只执行一次代码,那么我认为它不会满足我的要求。
but I'm not so sure that will work. Certainly if the preprocessor only goes through the code once then I don't think it'd work out the way I'd like.
我找到了几个类似的示例,但所有示例对我来说真的太复杂了。如果有人可以帮助我解决这个简单的问题,我将不胜感激!
I found several similar examples but all were really too complicated for me to understand. If someone could help me out with this simple one I'd be eternally grateful!
推荐答案简短的回答是。您可以嵌套这样的定义和宏-只要不递归就可以根据需要设置多个级别。
Short answer yes. You can nest defines and macros like that - as many levels as you want as long as it isn't recursive.
更多推荐
C宏定义可以引用其他宏吗?
发布评论