G++ 抱怨宏"does not give a valid preprocessing token",而 VC++ 编译良好
g++ complains "does not give a valid preprocessing token" on a macro while vc++ compiles fine
考虑下面的c++程序,它可以用vc++编译,但不能用g++编译
D:temp>cat test.cpp
#define SET_ALLIGN_FN(what)
void set_##what##_fn() { }
SET_ALLIGN_FN(Left);
#undef SET_ALLIGN_FN
template<class _Arg> struct Smanip{
Smanip(void( *pFun)(_Arg), _Arg val):m_pFun(pFun), m_val(val) { }
void( *m_pFun)(_Arg);
_Arg m_val;
};
template<> struct Smanip<void> {
Smanip(void( *pFun)()) : m_pFun(pFun) { }
void( *m_pFun)();
};
#define SET_ALLIGN(what)
static Smanip<void> ##what##Allign()
{ return (Smanip<void>(set_##what##_fn)); }
SET_ALLIGN(Left);
#undef SET_ALLIGN
int main() { }
D:temp>cl test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.61030 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
Microsoft (R) Incremental Linker Version 11.00.61030.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
D:temp>g++ test.cpp
test.cpp:15:23: error: pasting ">" and "Left" does not give a valid preprocessin
g token
static Smanip<void> ##what##Allign() { return (Smanip<void>(set_##what##_
fn)); }
^
test.cpp:16:5: note: in expansion of macro 'SET_ALLIGN'
SET_ALLIGN(Left);
^
我不明白的是为什么g++抱怨无效的令牌。编译器突出显示>
,但这不是宏生成的代码。
static Smanip<void> ##what##Allign()
您尝试连接>
和what
。尝试使用
static Smanip<void> what##Allign()
相关文章:
- 参考资源文件VC++中的$(SolutionDir)
- VC++本机单元测试,找不到调试符号
- Arduino无法编译名为SP:"Expected ')' before '(' token"的变量
- 为什么我的功能在使用 goto 时会给我带来"expected primary-expression before '}' token"?
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- VS2015 中的 VC++ 目录
- VS2015/VC++ 在新类模板中禁用默认 #include "stdafx.h"
- 如何解释 #if/#else 位域?(VC++菜鸟)
- 双线程应用比单线程应用慢 C++ (VC++ 2010 Express).如何解决?
- 使用线程 C# 中的 VC++ 6.0 COM DLL
- wcscpy 在 g++ 和 vc++ 中的不同行为
- STL 向量无缘无故损坏,VC++ 2017
- 使用结构和数组时的"expected primary expression before '.' token"
- VC++ wcscpy_s随机断言"Buffer is too small"
- 意外的模板与VC++中的std::void_t匹配
- 使用外部依赖项运行 VC++ 单元测试时"Failed to set up execution context"
- Microsoft VC++, vsnprintf, and Pipes (IO) Bug
- 如何打开和读取16位.raw文件Vc++(Wince 平台)
- 如何解决"Expected expression before " = " token"?
- G++ 抱怨宏"does not give a valid preprocessing token",而 VC++ 编译良好