gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 02:27:01 24 4
gpt4 key购买 nike

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

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

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com