I was surprised that gcc did not find an error in the following example. My understanding is that assignment to a void pointer is ok, but arithmetic is _not_ ok. I have tried this code on my arm cross compiler gcc v. 4.1.1 and my ubuntu system compiler 4.1.3. Gcc treats the void pointer type as char gcc --version gcc (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2) Example pointer arithmetic on a void pointer that should have caused an error #include <stdlib.h> int main (int argc, char **argv) { void *x; x = malloc(1025 * sizeof(*x)); x++; // i expected an error on this line! return 1; }
Created attachment 14694 [details] simple .c example
This is a GCC extension. Use -pedantic to get a warning, -pedantic-errors to get an error.
Subject: Re: New: pointer arithmetic on void pointers does not generate an error This is a GNU C extension, see <http://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html>. I think you can disable it with -std=c89 or -std=c99.