Compatible Type and Argument Type Classifiers

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); 

It's hard for me to find anything in the standard that covers the problem. What interests me most is the topic of whether it is really intended to prototype a function manually by omitting the restriction keyword, where the actual type may have limited arguments depending on the version of C or the version of other libraries used.

+4
source share
3 answers

Section C11 6.7.6.3 Β§15:

When determining compatibility between types and a composite type, each parameter declared using a function or array type is perceived as having an adjusted type, and each parameter declared using a qualified type is accepted as having an unqualified version of the declared Type .

+3
source

They are compatible:

(C99, 6.7.5.3 Declaration of functions (including prototypes) p15) "[...] (When determining the type of compatibility and composite type, each parameter declared using a function or array type is accepted as having an adjusted type, and each parameter is declared with qualified type is accepted as having an unqualified version of its declared type.) "

+4
source

The argument names in the prototype do not matter, so these definitions are equivalent. However, it is good practice to put names, as they should give an idea of ​​what the arguments are for. Technically, they are not needed, but serve as documentation.

Another thing is with the const qualifier, because it changes the value of the function.

+1
source

Source: https://habr.com/ru/post/1496873/


All Articles