Todd Freed
Todd Freed

Reputation: 933

How to declare a restricted function pointer argument

I can declare a function taking a function pointer as argument,

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

I can apply the const qualifier to this argument,

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

But when I apply the restrict qualifier to this argument, I get an error

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

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

I am using cc

0 % gcc --version
gcc (GCC) 7.3.0

Upvotes: 2

Views: 389

Answers (1)

a3f
a3f

Reputation: 8657

Only pointers to objects may be restrict qualified:

§6.7.3 Type qualifiers

  1. Types other than pointer types whose referenced type is an object type shall not be restrict-qualified.

A function is not an object:

§3.15.1 object

region of data storage in the execution environment, the contents of which can represent values

Upvotes: 3

Related Questions