I am trying to use a double void
pointer but I am a little bit confused about the usage.
I have a struct
that contains a void **
array.
struct Thing{
void ** array;
};
struct Thing * c = malloc (sizeof(struct Thing));
c->array = malloc( 10 * sizeof(void *) );
So If I want to assign a different object to each pointer and try to retrieve the value
// Option 1
*(c->array + index) = (void *) some_object_ptr;
// Option 2
c->array[index] = (void *) some_object_ptr;
then, I have another function that gives (void *) item
that points to each cell, not the some_object_ptr
.
If I want to retrieve the value which pointed to by some_object_ptr
,
should I do
function return type is 'void *' and takes argument 'void *'
// Option 3
return (void**) item
// Option 4
return *((void**)item)?
the weird thing is that when I used array the array subscript method I couldn't use option 4, only option 3; and when I used *(c->array + index)
I could only use opt.4. and not opt.3. ..
Can anyone please tell me about this? If I am making any invalid assumptions, then could you please correct me?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…