Reset struct alignment back to standard after each #pragma pack (n)

When using #pragma pack (n) to change the alignment for a struct
to n bytes, it is necessary to reset the alignment to the standard
value as otherwise the changed alignment is used throughout the
whole program code which causes other structs to become unaligned.
This commit is contained in:
John Paul Adrian Glaubitz
2018-05-18 23:44:40 +02:00
parent 5e490b279f
commit 2fb79510f0
4 changed files with 4 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ struct TempMBR {
struct MBRRecord partitions[4];
uint16_t MBRSignature;
}; // struct TempMBR
#pragma pack ()
// Possible states of the MBR
enum MBRValidity {invalid, gpt, hybrid, mbr};

1
bsd.h
View File

@@ -89,5 +89,6 @@ class BSDData {
int GetNumParts(void);
GPTPart AsGPT(int i); // Return BSD part. as GPT part.
}; // struct MBRData
#pragma pack ()
#endif

1
gpt.h
View File

@@ -57,6 +57,7 @@ struct GPTHeader {
uint32_t partitionEntriesCRC;
unsigned char reserved2[GPT_RESERVED];
}; // struct GPTHeader
#pragma pack ()
// Data in GPT format
class GPTData {

View File

@@ -50,6 +50,7 @@ struct MBRRecord {
uint32_t firstLBA; // see above
uint32_t lengthLBA;
}; // struct MBRRecord
#pragma pack ()
class MBRPart {
protected: