I want to read, edit, and write bmp files without any external libraries, using just standard C.
If I understand correctly, it is important that bytes are properly aligned to match the bmp file format.
However, I think I have also read somewhere on the internet that the compiler is allowed to pad struct
with extra bytes so I cannot always be sure exactly how many bytes my struct takes up, or even how the members are aligned within the struct.
How do I solve this issue using just standard C? Is there a syntax for asking the compiler to make sure my struct looks exactly the way I specify it?
How do I solve this issue using just standard C? Is there a syntax for asking the compiler to make sure my struct looks exactly the way I specify it?
The C standard does not provide a standard way to control struct layout. So, if you are dead set on only using what is specified by the standard, you cannot use structs to process Windows bitmap files.
To solve this using standard C you need to write/read byte arrays and serialize/deserialize them yourself.