如何声明受限函数指针参数

How to declare a restricted function pointer argument

我可以声明一个以函数指针为参数的函数,

int bar(int (* a)()) { } // this works

我可以将 const 限定符应用于此参数,

int bar(int (* const a)()) { } // this works

但是当我对这个参数应用 restrict 限定符时,我得到一个错误

int bar(int (* restrict a)()) { }

test.c:10:1: error: invalid use of ‘restrict’
 int bar(int (* restrict a)())

我正在使用 cc

0 % gcc --version
gcc (GCC) 7.3.0

只有指向对象的指针可以 restrict 合格:

§6.7.3 Type qualifiers

  1. 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