c****d 发帖数: 116 | 1 The packet is something like
struct packet
{
unsigned int a;
unsigned int b;
....
};
The size of the struct differs between 32-bit and 64-bit system.
how can I make it the same size across different platforms?
thanks |
t****t 发帖数: 6806 | 2 if your system has , you can use int8_t, uint32_t, etc. they are
guaranteed to be exactly that much wide.
【在 c****d 的大作中提到】 : The packet is something like : struct packet : { : unsigned int a; : unsigned int b; : .... : }; : The size of the struct differs between 32-bit and 64-bit system. : how can I make it the same size across different platforms? : thanks
|
c****d 发帖数: 116 | 3 thanks, let me try.
Otherwise, i will have to serialize it.
【在 t****t 的大作中提到】 : if your system has , you can use int8_t, uint32_t, etc. they are : guaranteed to be exactly that much wide.
|
d****i 发帖数: 4809 | 4 Use preprocessor directive to align the byte boundary on different hardware
systems
#pragma pack(1)
struct packet
{
unsigned int a;
unsigned int b;
....
};
This way compiler padding is disabled.
【在 c****d 的大作中提到】 : The packet is something like : struct packet : { : unsigned int a; : unsigned int b; : .... : }; : The size of the struct differs between 32-bit and 64-bit system. : how can I make it the same size across different platforms? : thanks
|
X****r 发帖数: 3557 | 5 然后出一个bus error ?
hardware
【在 d****i 的大作中提到】 : Use preprocessor directive to align the byte boundary on different hardware : systems : #pragma pack(1) : struct packet : { : unsigned int a; : unsigned int b; : .... : }; : This way compiler padding is disabled.
|
l*********s 发帖数: 5409 | 6 lol
【在 X****r 的大作中提到】 : 然后出一个bus error ? : : hardware
|