   Dynamic array of pointers within a structure in C?
  Just curious...Is it possible to create a struct containing an array of pointers that is alterable via realloc?   
  Sure, an array of pointers.  Of course for it to be dynamically sized you'd need a pointer.  Since each type itself is a pointer, what you end up with is a "double pointer" (is that a real term, I don't know).  So basically a void** points to the array, and each item would be a void*.   ;  Actually if the array of pointers is the last element in the struct then you can use flexible array members to have the array stored inline with the rest of the struct.   ;  Would you care to elaborate on that comment? Specifically, what do you mean by "flexible array members"?   ;Quote:Original post by LilBudyWizerWould you care to elaborate on that comment? Specifically, what do you mean by "flexible array members"?It's a somewhat sanctioned hack where you allocate extra space beyond the end of the structure to fit an array. It's even supported by a special syntax in C99:struct foo { int bar; char string[];};foo *p = malloc(sizeof(foo) + 4);strcpy(p->string, "...");Naturally this means that the variable length array must be at the end of the structure. You can do it manually too of course, usually by placing an array of one at the end and correcting the size manually when allocating memory.Here's another example from the WinAPI:typedef struct tagBITMAPINFO {    BITMAPINFOHEADER bmiHeader;RGBQUAD bmiColors[1]; } BITMAPINFO;Oh, and beware of alignment issues if you just try to tack the array on without adding a dummy member!   ;  Behold:#include <stdlib.h>struct FunkyStruct {  int  some_data;  int  probably_a_header;  char maybe_a_magic_cookie;  int * pointer_array[];};int main(void) {  struct FunkyStruct * funky = malloc(sizeof(struct FunkyStruct) +    sizeof(int *) * 4);  // funky has 4 pointers in pointer_array  funky->pointer_array[0] = NULL;  funky->pointer_array[1] = NULL;  funky->pointer_array[2] = NULL;  funky->pointer_array[3] = NULL;  funky = realloc(funky, sizeof(struct FunkyStruct) +   sizeof(int *) * 10);  // funky now has 10 pointers in pointer_array  funky->pointer_array[9] = NULL;  free(funky);  return 0;}The last member of the struct has a [] instead of an array bound which makes it a flexible array member. You can allocate memory and index based on dynamic size of the struct.   ;  Great!  Very useful info.  Grokking it now.   ;  Beware that you *cannot* make an array of these safely, and need to be quite careful when copying them. It's the same problem as passing values around in C++: object slicing.However, given an understanding of object slicing, and the ability to pass things around by pointer (not reference since you don't have those in C), it is a very useful too (commonly used for an OO hack for example).   