Further C front end tests

Joseph S. Myers joseph@codesourcery.com
Mon Nov 15 11:27:00 GMT 2004


On Sun, 14 Nov 2004, Zack Weinberg wrote:

> Hang on, this doesn't make sense.  Given void *p, the standard C
> definition of array indexing, and GCC's extension whereby void * is
> treated as char * for purposes of pointer arithmetic, p[0] reduces to
> *p.  If dereferencing a pointer to void is a constraint violation,
> then they are *both* ill-formed in our extended C.  If it isn't,
> neither is.

Array references have their own constraints (that the pointer be a pointer 
to object type) beyond those on unary * (that the type be a pointer type).  
Dereferencing void * by unary * is DR#106, which you implemented in 
<http://gcc.gnu.org/ml/gcc-patches/2000-07/msg00009.html>.

I'd understood the arithmetic-on-void* extension as applying to the 
constraint on binary + and -, not to the constraint on array reference 
(and the existing practice has already been that the part of the extension 
permitting arithmetic on function pointers doesn't apply to array 
references).  (Dereferencing void * in any case seems very dodgy, so 
having an extension providing an exception to the array reference 
constraints solely to allow such dereference looks of doubtful utility.  
But I'll change my next patch to condition diagnostics for array 
references to void types on pedantic || warn_pointer_arith.)

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)



More information about the Gcc-patches mailing list