Mail Archives: djgpp/1999/06/24/05:13:42
On 23 Jun 1999, Bart Alewijnse wrote:
> I have a struct with a 'void *data' member, of which the type I assign when
> I judge what data goes in it. The compiler yaks at me when I try to offset it
> like:
>
> to->data[offset]=0;
The compiler ``yaks'' at you because it cannot generate code for
`data[offset]' without knowing the size of `data'. For example, if
`data' points to an int, then each unit in `offset' increments the
pointer by 4, if it's a short, it increments the pointer by 2, etc.
A void pointer doesn't say anything about the size of the datum it
points to, so the compiler is helpless. To solve this, cast the data
to the correct type before dereferencing.
- Raw text -