Reputation: 1319
Is it dangerous/risky to use #pragma pack(1)
on structs that contain byte-arrays only? E.g. this one:
#pragma pack(1)
struct RpcMessage {
uint8_t proto_info[16];
uint8_t message_uuid[16];
uint8_t arg0[16];
uint8_t arg1[16];
uint8_t arg2[16];
uint8_t arg3[16];
uint8_t arg4[16];
uint8_t arg5[16];
uint8_t arg6[16];
uint8_t arg7[16];
uint8_t payload[65376];
};
(The idea is to cast this struct directly to/from 2^16 raw I/O bytes without any incompatibilities or even faults)
Upvotes: 0
Views: 673
Reputation: 213276
Given that each array has a size which is a multiple of the alignment, #pragma pack
won't do anything, as each array will automatically be properly aligned.
Upvotes: 2
Reputation: 213258
If the structure only contains uint8_t
, then #pragma pack(1)
will have no effect at all. It simply won’t do anything, because the structure is already packed as tightly as it can be.
Padding will only appear if you have elements which have larger than byte alignment.
Upvotes: 4