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. 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

Reply via email to