C中的变量名 [英] Variable names in C

查看:35
本文介绍了C中的变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在预处理器中,我们可以在宏之间切换,如

In preprocessors, we can have switch between macros like,

#define BUFF(n) BUFF_##n

因此,BUFF(1) 将被 BUFF_1 替换,BUFF(2) 将被 BUFF_2 和歌曲替换

So, BUFF(1) would get replaced by BUFF_1, BUFF(2) would get replaced by BUFF_2 and song

这是否适用于 C 变量?即,动态地在相似变量之间进行选择.我知道这是一个奇怪的情况,可以使用数组或任何其他结构来处理.

Can this be applicable to C variables? i.e., choosing between similar variables dynamically. I understand it is a weird situation and can be handled using arrays or any other constructs.. but the situation demands me such situation.. could u plz help with this.. thanks in advance

推荐答案

是的,您可以使用该宏将 BUFF_ 应用于任何事物.预处理器将展开宏,然后编译器将尝试编译结果.后者可能会失败,因为如果你使用 BUFF(+) 你会得到 BUFF_+ 而这不是一个有效的变量名.

Yes, you can use that macro to apply BUFF_ to just anything. The preprocessor will expand macros and then the compiler will try to compile the result. The latter might fail, since if you use BUFF(+) you get BUFF_+ and that's not a valid variable name.

这篇关于C中的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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