On Thu, Oct 8, 2009 at 8:32 AM, mayur nande <[email protected]> wrote:
> Hi Rick, > > Some days ago i had the same question in my mind. While going through "The > Linux Kernel Architecture" book (by Wolfgang Mauerer), i got the answer: > > The GNU compiler supports arithmetic with void pointers as well as function > pointers. The increment step is 1 byte. These are used by the kernel at > various points. > > Have fun. > > Regards > Mayur > > On Thu, Oct 8, 2009 at 7:42 AM, Rick Brown <[email protected]> wrote: > >> Hello list, >> >> As far as I recall from K&R, isn't pointer arithmetic on a void >> pointer banned? And any effort to do that results in an error - >> because the compiler won't know by how much size to increment the >> pointer for a statement like "ptr++"? But then how about this: >> >> [r...@linux rick]$ cat t.c >> #include <stdio.h> >> int main() >> { >> void *ptr = 0; >> printf("%d \n", ptr+1); >> } >> [r...@linux rick]$ gcc t.c >> [r...@linux rick]$ ./a.out >> 1 >> [r...@linux rick]$ >> >> It compiles and runs fine ... ! >> >> TIA, >> >> Rick >> >> -- >> To unsubscribe from this list: send an email with >> "unsubscribe kernelnewbies" to [email protected] >> Please read the FAQ at http://kernelnewbies.org/FAQ >> >> > Arithmetic on void and function pointers is part of GNU C extensions, C standard does not support it (size of void and functions is taken as 1). There are many such GNU extensions which are used in kernel. One way to figure out which all extensions are used is by providing -pedantic flag, this will emit warning for such usage. I think many of these extensions have became part of C99 standard already. Regards, Sandeep.
