On Wed, Aug 19, 2009 at 10:34:00AM +0200, Joerg Schilling wrote:
> Vincent Torri <vincent.torri at gmail.com> wrote:
> 
> > with a code similar to that one:
> >
> > int i = 2;
> > int j = 2;
> > void *a = &i;
> > void *b = &j;
> > unsigned long delta = a - b;
> >
> > the compiler is displaying the warning "pointer to void or function used in
> > arithmetic". Why is it doing so whe computing an offset ? I know that adding
> > or substracting an offset to a void pointer is illegal, but when calculating
> > an offset, using typed or void pointers is exactly the same.
> 
> A "void" is an "object" of unknown/unspecified size.
> 
> Pointer arithmetics for:
> 
>       delta = a - b;
> 
> -     means a and b need to be objects of the same type
> 
> -     the differentce between the numerical values in a and
>       b is computed
> 
> -     the result is divided by sizeof (a)
> 
> Did you ever try to use sizeof (void) in your code?
> 
> How do you like to divide by an unknown number?
> 
> A correct C-compiler does not print a warning but an error message and
> aborts compilation.

A correct C compiler (or as per C standard: conforming implementation) is 
required
to issue a diagnostics (ISO/IEC 9899:1999 (E) 5.1.1.3 Diagnostics). 
There is nothing in standard that requires compilation abort or non-zero exit 
code.
Issuing warning for a standard violation is fully standard conformant.

Typical rule for choosing warning vs error is to continue compilation if user 
intent 
is clear and "wrong" construct is nonambiguous.

regards,
  Fedor.

> What the sun compiler currently does is a courtesy
> to GCC users as GCC treats sizeof (void) == 1 which is in conflict with
> the C-standard. If the Sun compiler would work correctly and abort here,
> a lot of (broken) OSS software could not be compiled.
> 
> J?rg
> 
> -- 
>  EMail:joerg at schily.isdn.cs.tu-berlin.de (home) J?rg Schilling D-13353 
> Berlin
>        js at cs.tu-berlin.de                (uni)  
>        joerg.schilling at fokus.fraunhofer.de (work) Blog: 
> http://schily.blogspot.com/
>  URL:  http://cdrecord.berlios.de/private/ ftp://ftp.berlios.de/pub/schily
> _______________________________________________
> tools-compilers mailing list
> tools-compilers at opensolaris.org

Reply via email to