相关疑难解决方法(0)

为什么structof sizeof不等于每个成员的sizeof总和?

为什么sizeof操作员返回的结构尺寸大于结构成员的总尺寸?

c c++ struct c++-faq sizeof

644
推荐指数
11
解决办法
18万
查看次数

27
推荐指数
4
解决办法
11万
查看次数

为什么short在C中的结构中存储为4个字节?

我有以下两种结构:

问题是sizeof(内容)返回160.结构由11个短路,6个整数,76个字符,7个浮点数,1个双精度数组成,总共增加到158个字节.我已计数三次,仍有2个字节的差异.

typedef struct TIME_T { 
    short year,mon,day; 
    short hour,min,sec; 
} TIME;

typedef struct { 
    int no; 
    char name[20]; 
    char Code[10]; 
    char DASType[10]; 
    short wlen; 
    float VLtd; 
    int samp; 
    int comp; 
    int locationID; 
    short TranMode; 
    char TranIns[12]; 
    short TimerMode; 
    char ClkType[12]; 
    float ClkErr; 
    float lat; 
    float lon; 
    float alt; 
    float azimuth,incident; 
    short weight; 
    short veloc; 
    int oritype; 
    char seismometer[12]; 
    double sens; 
    TIME start_time; 
    int record_samples; 
} Content;
Run Code Online (Sandbox Code Playgroud)

我写了一小段代码来打印结构中每个变量的位置,然后突然发现float wlen需要4个字节.我的代码如下:

int main(void)
{   
    Content content;
    printf("Sizeof Content: %d\n", sizeof(content)); …
Run Code Online (Sandbox Code Playgroud)

c struct sizeof

2
推荐指数
2
解决办法
3861
查看次数

标签 统计

c ×3

sizeof ×3

struct ×3

c++ ×1

c++-faq ×1