Date: Thu, 24 Jun 1999 12:10:58 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Bart Alewijnse cc: djgpp AT delorie DOT com Subject: Re: Dereferencing a void pointer In-Reply-To: <01bebdc4$9b2e6020$LocalHost@scarfboy.tip.nl> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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.