Message-ID: <34D12BC6.6369@compuserve.com> Date: Thu, 29 Jan 1998 20:24:22 -0500 From: Laurent Turcotte MIME-Version: 1.0 Subject: Re: HELP: accessing astructure members via VOID pointer?? References: <34CD4681 DOT 3747 AT cam DOT org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Newsgroups: comp.os.msdos.djgpp Lines: 44 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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 <-- Hi Vic You should look at the assembly output of your C code because I think the compiler generate code like what you are trying to do example: struct { int a; int b; } S; struct S *Ptr; Ptr->a = 3; will be compiled to something like movl $3, (Ptr) Ptr->b = 5; will be compiled to movl $5, 4(Ptr) .. I hope the ATT syntax is ok ! Regards Laurent Turcotte