在宏中生成包含文件名 [英] Generate include file name in a macro

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

问题描述

我想在宏中生成包含文件名。这在C ++中是合法的:

I'm trying to generate include file name in macro. This is supposed to be legal in C++:

#define INCLUDE_FILE "module_impl_win.hpp"
#include INCLUDE_FILE

这很好,但是一旦我尝试生成文件名,它就无法编译

this works fine, but as soon as I try to generated file name it failes to compile

#define INCLUDE_FILE(M) M##"_impl_win.hpp"
#include INCLUDE_FILE("module")

其实它在MSVC2010上给予警告

Actually it gives me warning on MSVC2010


警告C4067:预处理器伪指令后出现意外令牌 - 预期为newlin

warning C4067: unexpected tokens following preprocessor directive - expected a newlin

,但不包括该文件。

有什么问题?如何摆脱它?

What is the problem? How can I get rid of it?

推荐答案

我会使用帮助引用宏。这样的东西会给你你想要的:

I'd do this using a helper quoting macro. Something like this will give you what you want:

#define QUOTEME(M)       #M
#define INCLUDE_FILE(M)  QUOTEME(M##_impl_win.hpp)

#include INCLUDE_FILE(module)

这篇关于在宏中生成包含文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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