How void pointer arithmetic is happening in GCC

流过昼夜 提交于 2019-11-28 11:46:15

C does not allow pointer arithmetic with void * pointer type.

GNU C allows it by considering the size of void is 1.

From 6.23 Arithmetic on void- and Function-Pointers:

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.

http://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Now to answer this question:

Also, why dereferencing is not possible for void pointer, if it is implicitly doing pointer arithmetic.

GNU C allows pointer arithmetic with void * but still does not allow an object of type void to be declared.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!