I have the need to allocate memory for an array of pointers to structs. The documentation for malloc()
informs that the return from this function returns a pointer to the first block of memory that was allocated. Well, in my case I called the function like this:
malloc(SIZE_TABLE*sizeof(struct structName*))
The problem being that, since malloc returns a pointer to this memory (containing pointers), it will thus return a 2-star pointer of type structName
.
Instead of having an extra line to assign the 2-star pointer and then dereference it, can you dereference the call itself?
Instead of:
struct structName** temp = malloc(SIZE_TABLE*sizeof(struct structName*))
struct structName* temp2 = *(temp);
Could you do something like:
struct structName* temp2 = *( malloc(SIZE_TABLE*sizeof(struct structName*)) );
I have done little when it comes to 2-star pointers, so if there is a better way to approach this problem (or if I am simply miss-understanding it all), please let me know.