Re: C question
mayur nande <[email protected]>
| Newsgroups | gmane.linux.kernel.kernelnewbies,gmane.linux.newbie |
|---|---|
| Message-ID | <[email protected]> |
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: > > [rick@linux rick]$ cat t.c > #include <stdio.h> > int main() > { > void *ptr = 0; > printf("%d \n", ptr+1); > } > [rick@linux rick]$ gcc t.c > [rick@linux rick]$ ./a.out > 1 > [rick@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 > >