Pointer arithmetic requires a type.  The number that you add to the pointer
is multiplied by the size of the type.  So:

char *ptr + 5 is the address of ptr + 5 bytes;
int *ptr + 5 is the address of ptr + 5 * 4 bytes (assuming 4byte integers)

Void * essentially declares that you don't know the type.


> -----Original Message-----
> From: Richard Hartman [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 19, 1999 6:33 PM
> To: '[EMAIL PROTECTED]'
> Subject: Pointer Arithmetic in CW5
>
>
>
> I'm having a problem w/ what should be simple
> pointer arithmetic ... the compiler just won't
> let me do it!  I've pared down the problem, doing
> things step by step until I get the error on one
> operation (the math).  It's giving me an "Error :
> illegal type" on the line marked with ">>>"
>
>       void *p = pDbRec;               // cast rec ptr to void ptr to
> simplify things
>       UInt o = pDbRec->hdr.bDataOffset;       // put offset into single
> variable
>                                                       // to simplify
> things
> >>>   void *p2 = p + o;               // add offset to ptr, kablooie!
>
>
> Maybe it's just too late in the day ... but what
> am I doing wrong?
>
> --
> -Richard M. Hartman
> [EMAIL PROTECTED]
>
> 186,000 mi./sec ... not just a good idea, it's the LAW!
>
>
>

Reply via email to