I'm using the macro container_of defined as:
#define container_of(ptr, type, member) ((type *)((char *)(1 ? (ptr) : &((type *)0)->member) - offsetof(type, member)))
the structure vector:
struct vector {
uint32_t signature;
size_t element_size;
size_t size;
void *data;
};
And finally the function vectorSize
receiving a pointer to some data. This function is not working because only the data member inside struct vector v have the right value, the others have garbage, resulting in failing the if statement SIGNATURE.
size_t vectorSize(void *vec)
{
void **pdata = &vec;
struct vector *v = container_of(pdata, struct vector, data);
if (v->signature != VECTOR_SIGNATURE) return 0;
return v->size;
}
What is wrong with my setup?