Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compatible types and argument type qualifiers

Are the types of these two declarations compatible types?

void f(char *, char *);
void f(char *restrict, char *restrict);

or similarly:

void g(char *);
void g(char *const);

I'm having a hard time finding anything in the standard which covers the issue. I'm mostly interested in the topic of whether it's valid to manually prototype a function, omitting the restrict keyword, where the actual type might have restrict-qualified arguments depending on the version of C or version of other libraries in use.

like image 514
R.. GitHub STOP HELPING ICE Avatar asked Aug 13 '13 17:08

R.. GitHub STOP HELPING ICE


People also ask

What is compatible type?

In C, compatible types are defined as: two types that can be used together without modification (as in an assignment expression) two types that can be substituted one for the other without modification.

What is meant by type qualifier?

A type qualifier is used to refine the declaration of a variable, a function, and parameters, by specifying whether: The value of an object can be changed. The value of an object must always be read from memory rather than from a register. More than one pointer can access a modifiable memory address.


2 Answers

They are compatible:

(C99, 6.7.5.3 Function declarators (including prototypes) p15) "[...] (In the determination of type compatibility and of a composite type, each parameter declared with function or array type is taken as having the adjusted type and each parameter declared with qualified type is taken as having the unqualified version of its declared type.)"

like image 85
ouah Avatar answered Sep 30 '22 09:09

ouah


C11 section 6.7.6.3 §15:

In the determination of type compatibility and of a composite type, each parameter declared with function or array type is taken as having the adjusted type and each parameter declared with qualified type is taken as having the unqualified version of its declared type.

like image 22
Christoph Avatar answered Sep 30 '22 09:09

Christoph