On Wed, Aug 19, 2009 at 10:34 AM, Joerg Schilling <
Joerg.Schilling at fokus.fraunhofer.de> 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. 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.
>

hoo, right ! i've forgotten that it divides by the size of variables (and it
can be negative too)

thank you to both of you !

Vincent Torri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.opensolaris.org/pipermail/tools-compilers/attachments/20090819/ca69ec19/attachment.html>

Reply via email to