由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 怎样能让这个结构在32 或64 位系统大小一样?
相关主题
how to apply OOD to a code for both win and linux platform ?python 超级难题求救
Another questionC语言,结构体转字符串。简单的难题
定义的struct数组很大时,为什么会出现奇怪的大数字?difference between FILE and struct FILE
what's this mean in C program? ":" in identiferC & C++ mixing question
一个简单的C编程问题请教一下,怎么控制发送UDP的速度?
请教一个C的问题mysql频繁写的时候老是挂掉,应该怎么办?
python question, easy oneQuestion on using ## in #define
问个c++ struct的土问题三个C syntax 弱问题
相关话题的讨论汇总
话题: unsigned话题: packet话题: struct话题: int话题: bit
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
三个C syntax 弱问题一个简单的C编程问题
#ifdef, #ifndef 这些 preprocessor 应该叫什么呀?请教一个C的问题
一个简单的小问题python question, easy one
one question about operator delete问个c++ struct的土问题
how to apply OOD to a code for both win and linux platform ?python 超级难题求救
Another questionC语言,结构体转字符串。简单的难题
定义的struct数组很大时,为什么会出现奇怪的大数字?difference between FILE and struct FILE
what's this mean in C program? ":" in identiferC & C++ mixing question
相关话题的讨论汇总
话题: unsigned话题: packet话题: struct话题: int话题: bit