Vincent Torri 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;
s/unsigned long/ptrdiff_t/ Note that the difference may be negative, e.g. the datatype must be |signed| (usually you should use the standard type |prtdiff_t| (e.g. this integer datatype is guranteed to hold the full difference between two pointers)) ... > 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. Erm... AFAIK the difference of pointers of the same type counts "objects", not "bytes", e.g. if you compute the offset of two |long *|-pointers you get the difference in "number of |long| elements", if you use |long double *| you'll get the difference in "number of |long double| elements" etc. If you want the difference in |bytes| you should cast both pointers to |char *| first. ---- Bye, Roland -- __ . . __ (o.\ \/ /.o) roland.mainz at nrubsig.org \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer /O /==\ O\ TEL +49 641 3992797 (;O/ \/ \O;)