由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - sizeof()的问题
相关主题
ask a question about struct in C programming[合集] Interview Question
请教一个c++ 里functor的问题typedef
C++里get array size的问题 (转载)typedef struct的问题
how to initialize this struct.一个简单的C编程问题
为啥有人喜欢把_s结尾的结构typedef成_t结尾的,有讲究么?有段c++代码看不懂
请教函数 INIT 怎么能free memory问个编程,系统,网络有关的综合问题。
difference between FILE and struct FILEtypedef 的一个问题
请问可以这样定义struct吗?请教一个rpcgen的问题
相关话题的讨论汇总
话题: sizeof话题: test话题: double
进入Programming版参与讨论
1 (共1页)
z***f
发帖数: 121
1
typedef struct
{
double
double
int
} TEST
sizeof(TEST)怎么是24,而不是20呢?
sizeof(double)+sizeof(double)+sizeof(int) != sizeof(TEST)?
P****i
发帖数: 12972
2
google byte alignment

【在 z***f 的大作中提到】
: typedef struct
: {
: double
: double
: int
: } TEST
: sizeof(TEST)怎么是24,而不是20呢?
: sizeof(double)+sizeof(double)+sizeof(int) != sizeof(TEST)?

i******l
发帖数: 270
3
为了对齐
你可以尝试打出结构中每个变量的地址
就会发现结构的内存布局不是象你想的那样
是连续的,而是有空隙的

【在 z***f 的大作中提到】
: typedef struct
: {
: double
: double
: int
: } TEST
: sizeof(TEST)怎么是24,而不是20呢?
: sizeof(double)+sizeof(double)+sizeof(int) != sizeof(TEST)?

1 (共1页)
进入Programming版参与讨论
相关主题
请教一个rpcgen的问题为啥有人喜欢把_s结尾的结构typedef成_t结尾的,有讲究么?
One question about Void pointer请教函数 INIT 怎么能free memory
Questions about c codedifference between FILE and struct FILE
用c怎么实现generic stack (转载)请问可以这样定义struct吗?
ask a question about struct in C programming[合集] Interview Question
请教一个c++ 里functor的问题typedef
C++里get array size的问题 (转载)typedef struct的问题
how to initialize this struct.一个简单的C编程问题
相关话题的讨论汇总
话题: sizeof话题: test话题: double