If I write a structure (or class) likecan I safely make any assumptions about whether, where, and how much padding will be added?Code:struct rvBitmap { //fileheader follows (14 bytes): unsigned char magic1; // Magic number 'BM' 2 bytes unsigned char magic2; unsigned int fileSize; // 4 bytes unsigned short res1; // Reserved (0) 2 bytes unsigned short res2; // Reserved (0) 2 bytes unsigned int offset; // Offset to image data 4 bytes //infoheader follows (40 bytes): unsigned int infoSize; // infoheader size 4 bytes int imgWidth; // 4 bytes int imgHeight; // 4 bytes unsigned short planes; // 2 bytes unsigned short bitsPerPixel; // 2 bytes unsigned int compression; // 4 bytes unsigned int imgSize; // 4 bytes int xResolution; // 4 bytes int yResolution; // 4 bytes unsigned int nColors; // 4 bytes unsigned int nImportant; // 4 bytes vector<unsigned char> pixels; ...[constructors & other methods] }
For example, can I assume that the 40 bytes beginning with infoSize and ending with nImportant will be contiguous in memory?
Are there general rules about this, or is it all compiler- or OS-specific?