c - Why isn't GCC's acceptance of void-pointer arithmetic considered a bug? -


there @ least 3 different posts how void pointer arithmetic prohibited in c; gcc 4.8.2 allows it, assuming void of byte size; , how 1 can turn on pedantic warnings trigger error. ok. here example:

#include <stdio.h>  /* compile gcc -wall -o try try.c */  int main() {   char *str="string";   void *vp= (void *) str;    ++vp; /* arithmetic on void point.  huh? */    printf("%s\n", (char*)vp);   return 0; } 

but question thinking c compiler supposed in case of invalid code. not considered bug when compiler not issue compile error on invalid code?

and seems bizarre behavior compiler, anyway---even if gcc not issue compile error, @ least, issue "deprecated" warning default compiler flags. and, -wall, still not giving warning. huh? surprised me because gcc seems mature otherwise , c not novel or complex language.

the c standard makes attempt perform pointer arithmetic on void* constraint violation, means conforming c compiler must issue @ least 1 diagnostic message program containing such attempt. warning may non-fatal error; in case, compiler may go on generate code behavior defined implementation.

gcc, default, not warn pointer arithmetic on void*. means gcc, default, is not conforming c compiler.

one argue bug, in default mode gcc not compiler standard c gnu c. (a fortran compiler's failure conforming c compiler not bug.)

carefully chosen command-line options can force gcc @ least attempt conforming. example:

gcc -std=cxx -pedantic 

where xx 1 of 90, 99, or 11, cause gcc warn pointer arithmetic on void*. replacing -pedantic -pedantic-errors causes treat such arithmetic fatal error.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -