I am trying to find out if the following forward declaration is valid in ANSI-C:
First file:
extern void * fptr; // opaque forward declaration.
int main (void) {
fptr = NULL; // set the function pointer to NULL
}
Second file:
typedef int (*fptr_t)(int);
fptr_t fptr; // real declaration of the function pointer
To me, this should be invalid since fptr
if declared with two different types, but neither gcc
nor clang
gives any warning.
I would be more specifically interested in precise points of the C11 standard that allow to conclude why it is valid (or invalid).
EDIT: in the C11 standard,6.2.7:2 says:
All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined.
But I cannot find how to decide if void*
is compatible with fptr_t
.