Hi there!
I have to use strange structs that looks like this:
As everyone can see, it seems to be a choice of design that the size of the struct "Any" has to be determined in run-time. But the problem is that the container struct carries that struct somewhere in the middle so I cannot use the workaround allocating enough memory for the container struct because I would overwrite the following components.
But on the other hand I am neither able to reallocate nor to move the pointer to the "Any" struct to a seperate, previously allocated "Any" struct.
Please take a look at my sample code and give me a hint. I am stuck here...
I have to use strange structs that looks like this:
Code:
typedef struct Any
{
int length;
char value[1]; /* first element of the array */
} Any;
typedef struct Container
{
/* ... some other structs ...*/
Any a_any;
/* ... some other structs ...*/
} Container;
As everyone can see, it seems to be a choice of design that the size of the struct "Any" has to be determined in run-time. But the problem is that the container struct carries that struct somewhere in the middle so I cannot use the workaround allocating enough memory for the container struct because I would overwrite the following components.
But on the other hand I am neither able to reallocate nor to move the pointer to the "Any" struct to a seperate, previously allocated "Any" struct.
Please take a look at my sample code and give me a hint. I am stuck here...
Code:
static const char text[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
};
int _tmain(int argc, _TCHAR* argv[])
{
Container* c = (Container*) malloc(sizeof(Container));
Any* any = (Any*) malloc(sizeof(Any)+100);
any->length = 10;
memcpy(&any->value, text, 10);
&c->a_any = any; // I want to do sth. like this...
return 0;
}