Following are 2 different interpretations:
char c; // 1
struct MyChar { char c; }; // 2
If I do new MyChar[100], will it allocate 100 bytes in all platform ? Adding non-virtual constructor/destructor and/or operators will make any effect on the size of MyChar ?
MyChar may have unnamed padding bytes after c, so no, it isn't guaranteed that sizeof(MyChar) is 1.
On MSVC, you can use:
#pragma pack(1)
struct MyChar
{
char c;
};
// Restore
#pragma pack()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With