delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/27/15:33:23

Message-ID: <34CE51E3.79C09F2C@jet.es>
Date: Tue, 27 Jan 1998 21:30:11 +0000
From: "Jordi Pérez" <jordimln AT jet DOT es>
MIME-Version: 1.0
To: Vic <tudor AT cam DOT org>
CC: djgpp AT delorie DOT com
Subject: Re: HELP: accessing astructure members via VOID pointer??
References: <34CD4681 DOT 3747 AT cam DOT org>

Vic wrote:

> Hello. I'd like to be able to do something like this:
> I have a struct foo (int x,y,z) and a void* bar=&foo;
> So bar holds the adress of foo. I know that at the beginning of the
> struct lies the first member. so why can't I just say *bar=55 or
> something?
> I'd like to be able to access any member of a struct using a pointer.
> Like, if I want to access the second member, I add 4(or whatever) to
> the
> pointer and write the value to that adress. How could I do that?
> HELP!!
> TIA,
> --
> --> http://www.cam.org/~tudor <--

With -> you can acces any type of struct from a void pointer;
Well, you just need to acces to variables in the struct in the next way:

    bar->x=55;

Jordi Pérez Bou,               jordimln AT jet DOT es
alternative e-mail:            e6707357 AT est DOT upc DOT es
/**********************************************(Excuse my english)


- Raw text -


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