delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/24/05:13:42

Date: Thu, 24 Jun 1999 12:10:58 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Bart Alewijnse <scarfman AT geocities DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Dereferencing a void pointer
In-Reply-To: <01bebdc4$9b2e6020$LocalHost@scarfboy.tip.nl>
Message-ID: <Pine.SUN.3.91.990624121040.25071P-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019