【发布时间】:2021-12-28 22:34:31
【问题描述】:
我正在使用 gcc/g++。下面的代码使用gcc -S test.c 编译得很好,但是使用g++ -S test.cpp 我得到error: requested alignment is not an integer constant。如果我查看两者的预处理器输出,它看起来是相同的。所以我的问题是为什么 ALIGN_BYTES 在 C++ 案例中不被预处理器评估为常量 64? (如果我用常量 64 替换 ALIGN_BYTES 就可以了)
/* test.c, test.cpp */
#define BITS 512
#define ALIGN_BYTES (BITS / 8)
#define ALIGN __attribute__ ((aligned(ALIGN_BYTES)))
typedef char* ALIGN char_PT;
【问题讨论】:
-
删除了之前的评论,
#define ALIGN alignas(ALIGN_BYTES)确实解决了这个问题。谢谢
标签: c++ c gcc g++ c-preprocessor