looking at:
struct post{
unsigned int isImg : 1;
struct img
{
char *name;
char *url;
int likes;
};
unsigned int isTxt : 1;
struct text
{
char*text;
int likes;
};
union Data
{
struct img Img;
struct text Txt;
} data;
};
I see a few problems:
- the definition of first 32 bit bitmap, only one bit defined
- the 'img' struct is 12 bytes+4bytes filler
- the definition of second 32 bit bitmap, only one bit defined
- the 'text' struct is 8 bytes+8bytes filler
- the union, composed of the two prior struct types
- all defined with an enclosing struct
This is very poor organization of the data declarations.
suggest:
struct img //32bits
{
char *name;
char *url;
int likes;
};
struct text //32bits
{
char *text;
int likes;
};
union Data // 32bits
{
struct img Img;
struct text Text;
};
struct post //5*32bits
{
unsigned int isImg : 1;
struct img image;
unsigned int isTxt : 1;
struct text Text;
union Data data;
};
even with the above (which compiles with no errors/warnings) there is still the problem that a bitmap ordering is implementation defined, so you do not know, without testing, if those defined bits are the MSB or the LSB of the bitmap.