如何实现为_Pragma创建带引号的字符串的宏? [英] How do I implement a macro that creates a quoted string for _Pragma?

查看:104
本文介绍了如何实现为_Pragma创建带引号的字符串的宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个这样调用的宏:

I want to have a macro that's invoked like this:

GCC_WARNING(-Wuninitialized)

扩展为以下代码:

_Pragma("GCC diagnostic ignored \"-Wuninitialized\"")

我没有运气,因为预处理器连接和字符串化的通常技巧似乎并不适用,或者我不知道如何在此处应用它们.

I'm not having luck getting this to work, as the usual tricks of preprocessor joins and stringifying don't seem to apply or I don't know how to apply them here.

推荐答案

在预处理器魔术的帮助下:

With the little help of preprocessor magic:

#define HELPER0(x) #x
#define HELPER1(x) HELPER0(GCC diagnostic ignored x)
#define HELPER2(y) HELPER1(#y)
#define GCC_WARNING(x) _Pragma(HELPER2(x))

GCC_WARNING(-Wuninitialized)

这篇关于如何实现为_Pragma创建带引号的字符串的宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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