Mail Archives: djgpp/1998/01/30/00:31:22
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
- Raw text -