This program compiles without errors, for example with clang -Wall -std=c11 a.c
and gcc -Wall -std=c11 a.c
. Is this a bug in clang and gcc? Because ari
Add the -Wpointer-arith
flag to produce warnings
a.c:8:22: warning: arithmetic on a pointer to the function type 'void (void)' is a GNU extension [-Wpointer-arith]
printf("%p\n", p + 1);
~ ^
From GNU documentation
In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1.
Clang -Wpointer-arith documentation
warning: arithmetic on a pointer to the function type B is a GNU extension
Function pointer arithmetic is a gcc extension also implemented by clang.
To invoke standards compliance you need
gcc -std=c11 -pedantic ...
clang -std=c11 -pedantic ...