GCC 预处理器宏和“#pragma GCC unroll”

问题描述 投票:0回答:1

是否有另一种机制可以让预处理器执行此操作:

#define LIMIT  16
#pragma GCC unroll LIMIT
for (size_t ii = 0; ii < LIMIT; ++ii) {
  ...

该代码遇到错误:

/path/to/my/file.c:100:20 error: 'LIMIT' undeclared (first use in this function)
  100 | #pragma GCC unroll LIMIT
      |                    ^~~~~

gcc documentation 说这需要

an integer constant expression specifying the unrolling factor
。我相信我的宏是一个“整数常量表达式”,但是......

我的编译器是:

riscv64-unknown-elf-gcc (g2ee5e430018) 12.2.0

c++ c gcc c-preprocessor preprocessor
1个回答
0
投票

const
constexpr
(如果你可以使用C++)似乎可以工作(在https://godbolt.org/上使用gcc 13.2进行测试)。

const int x = 5;
#pragma GCC unroll x
for (std::size_t ii = 0; ii < x; ++ii) {
© www.soinside.com 2019 - 2024. All rights reserved.