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

标签 c function-pointers restrict

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

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

  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

关于c - 如何声明受限函数指针参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49600502/

相关文章:

c - 从不兼容的指针类型传递 qsort 的参数 4

c++ - 在c/c++中非阻塞写入文件

c - 尝试使用指针在数组中插入元素,但未成功

c - 对数组使用限制?

ios - 如何在控制中心检测蓝牙是否真的关闭(或蓝牙开关按钮关闭)

c - 我的字符串生成程序出了什么问题?

c++ - C函数指针参数打印问题

linux - 获取函数指针以在我没有直接加载的共享库中运行

c++ - 具有不同签名的函数数组

C++ 限制语义