In program C, I have a structure
typedef struct { void *payload;
To create some type of security veneer, I could create getters and setters
CbData *get_cb_data(const MiddleMan *mm){ return mm->payload; } void set_cb_data(MiddleMan *mm, CbData *cbd){ mm->payload = cbd; }
Or I can try to do this with one based on access pointers
CbData **cb_data(MiddleMan *mm){return (CbData**)&mm->payload;}
Now the second solution looks rougher than the first, and also restricts users to non-constant mm , even if they just want to read. But my question is, is this even legal C?
I'm sure you can get away from it in any architecture where void* has the same size and format as CbData* . But can anyone give a clear explanation why this (or not) is really at all?
source share