H
harshal
Hi all,
i have 2 structures say struct a, and struct b
i am in a function now in this function i want to store these 2
pointers
in global memory and store that address in void pointer.
void abc(void *temp) {
struct a * aptr;
struct b * bptr;
// get these pointers filed from temp
aptr = (struct a *) temp;
temp = temp + (sizeof(struct a *));
bptr = temp;
// i am confused about this.
}
void collect(struct collector *e) {
struct a *aptr = NULL;
struct b *bptr = NULL;
void * temp = NULL;
// suppose these two pointers are filled with appropriate values by
iterating a list aptr and bptr
// are ok now
temp = malloc(2 * sizeof(void *));
temp = aptr;
temp = temp + sizeof(struct a *);
temp = bptr;
//then decrement temp again to get original value
temp = temp - sizeof(struct a *);
//and pass this pointer to other function i dont want to send them
as an parameter
abc(temp);
}
is this right??
i forgot everything about void pointers but i know that we can not do
arithmetic operations on void ptr and if we do it will be like char
ptr and we can not dereference it also.
and please guide me through how abc will collect these two pointers in
local variables also
Thanks
i have 2 structures say struct a, and struct b
i am in a function now in this function i want to store these 2
pointers
in global memory and store that address in void pointer.
void abc(void *temp) {
struct a * aptr;
struct b * bptr;
// get these pointers filed from temp
aptr = (struct a *) temp;
temp = temp + (sizeof(struct a *));
bptr = temp;
// i am confused about this.
}
void collect(struct collector *e) {
struct a *aptr = NULL;
struct b *bptr = NULL;
void * temp = NULL;
// suppose these two pointers are filled with appropriate values by
iterating a list aptr and bptr
// are ok now
temp = malloc(2 * sizeof(void *));
temp = aptr;
temp = temp + sizeof(struct a *);
temp = bptr;
//then decrement temp again to get original value
temp = temp - sizeof(struct a *);
//and pass this pointer to other function i dont want to send them
as an parameter
abc(temp);
}
is this right??
i forgot everything about void pointers but i know that we can not do
arithmetic operations on void ptr and if we do it will be like char
ptr and we can not dereference it also.
and please guide me through how abc will collect these two pointers in
local variables also
Thanks