我可以声明一个以函数指针作为参数的函数,
int bar(int (* a)()) { } // this works
我可以将 const 限定符应用于此参数,
int bar(int (* const a)()) { } // this works
但是当我将限制限定符应用于此参数时,我收到错误
int bar(int (* restrict a)()) { }
test.c:10:1: error: invalid use of ‘restrict’
int bar(int (* restrict a)())
我正在使用抄送
0 % gcc --version
gcc (GCC) 7.3.0
最佳答案
只有指向对象的指针才可以被restrict
限定:
§6.7.3 Type qualifiers
- Types other than pointer types whose referenced type is an object type shall not be restrict-qualified.
函数不是对象:
§3.15.1 object
region of data storage in the execution environment, the contents of which can represent values
关于c - 如何声明受限函数指针参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49600502/