C宏定义可以引用其他宏吗?

编程入门 行业动态 更新时间:2024-10-25 06:26:14
本文介绍了C宏定义可以引用其他宏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要弄清楚的是这样的东西(用 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宏定义可以引用其他宏吗?

本文发布于:2023-11-23 18:28:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622451.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!