开发者

Variable names in C

In preprocessors, we can have switch between macros like,

#define BUFF(n) BUFF_##n

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

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.. 开发者_StackOverflowcould u plz help with this.. thanks in advance


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.


Sure, you can do this. preprocessor macros are just text replacements that are done to the code before compilation. You can't do this during runtime, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜