您可以在宏中将粘贴的标记大写吗? [英] Can you capitalize a pasted token in a macro?

查看:16
本文介绍了您可以在宏中将粘贴的标记大写吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C 宏中,是否可以将粘贴的标记大写?例如,我目前有以下宏:

In a C macro, is it possible to capitalize a pasted-in token? For example, I currently have the following macro:

#define TEST(name, keyword) 
    test_##name:
        TEST_##keyword##_KEYWORD

我会这样调用它:

TEST(test1, TEST1)

这将产生以下结果:

test_test1:
    TEST_TEST1_KEYWORD

现在,我不必输入两次相同的名称(一次全部为小写字符,一次全部为大写字符),有什么方法可以执行以下任一操作,或者将令牌更改为全部大写还是全部小写?

Now, instead of having to type the same name twice (once with all lower case characters, and again with all upper case characters), is there any way that I could do either of the following, and either change the token into all uppercase letters or all lowercase letters?

TEST(test1) or TEST(TEST1)

谢谢,瑞恩

推荐答案

据我所知,在 C 预处理器(至少 ISO/ANSI 标准)中唯一可以对令牌执行的操作是替换,'stringify' 或连接它们.我也不知道有任何 GCC 或 MSVC 扩展可以让你做你想做的事.

As far as I'm aware, the only operations that can be done on tokens in the C preprocessor (at least ISO/ANSI standard) is to replace, 'stringify' or concatenate them. I'm also unaware of any GCC or MSVC extensions that will let you do what you want.

然而,人们一直在想出聪明(或古怪)的方法来用宏做神奇(或可怕)的事情,所以如果有人让我感到惊讶,我不会感到惊讶.

However, people have been coming up with clever (or oddball) ways to do magical (or horrible) things with macros, so I wouldn't be surprised if someone surprises me.

这篇关于您可以在宏中将粘贴的标记大写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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