c++ #elif指令被丢弃
C++ #elif directive is being discarded
我正在尝试创建一个基于边界的类型声明
template<class B>
struct IntDecl {
enum {
L = B::_l, U = B::_u
};
#if (L >=0 && U <=255)
typedef char Type;
#elif (L>=0&&U<=65535)
typedef unsigned int Type;
#endif
};
因此,正如您在这里看到的,根据L
和U
的值来定义类型。例如
IntDecl< BOUND < 0, 65535 > >::Type i; // this should be a unsigned int
IntDecl< BOUND < 0, 255 > >::Type i1; // this should be a char
问题是,(i
和i1
)都被认为是chars
,换句话说,#elif
被丢弃了。任何帮助吗?为什么#elif
没有执行?
预处理过程在语义分析之前进行,enum是一个语义结构。您需要使用模板来实现这一点,或者创建定义预处理器常量的L
和U
宏。
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- C++:对不存在的命名空间使用命名空间指令
- 函数名是c中该函数的第一条指令的地址吗
- 错误:无效的预处理指令 #i 的意思是 #if?
- 组装指令中乘法的下部和上部是什么
- OpenMP 与有序和关键指令并行
- C++中的移动分配出现问题.非法指令: 4.
- 嵌套命名空间的"using"指令,但需要命名内部命名空间
- C++CMake编译指令与
- 使用宏扩展的泛型:为什么指令缓存使用不当?
- 如何在 c++ 中确定一条指令(以字节为单位)在哪里结束,另一条指令从哪里开始?
- AVX 指令中寄存器和指针之间的客观差异
- while 循环 c++ 中的非法指令
- 如何在编译时定义C++预处理器指令的值?
- 存储指令是否会阻止缓存未命中的后续指令?
- 保证编译器指令在C++中重新排序
- VS2008中的AVX-512指令库
- 令人困惑的定义指令在C ++项目中
- c++ #elif指令被丢弃