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

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

问题描述

在一个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

我将调用此,如下所示:

I would invoke this as follows:

TEST(test1, TEST1)

这将产生以下

which would yield the following:

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标准)是取代的唯一操作, 字符串化"或将它们连接起来.我也知道任何海合会或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天全站免登陆