ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Понедельник
26 августа
484013
fk0, легенда (28.01.2014 21:20, просмотров: 5599)
Как d выравнять на границу sizeof(int) ? Менять тип d -- нельзя. 
sizeof(struct s)=8
offsetof(struct s, a)=0
offsetof(struct s, c)=4
offsetof(struct s, d)=5
#include <stdio.h> #include <stddef.h> struct s { int a; // short b; char c; char d[]; }; int main() { printf("sizeof(struct s)=%u\n", sizeof(struct s)); printf("offsetof(struct s, a)=%u\n", offsetof(struct s, a)); // printf("offsetof(struct s, b)=%u\n", offsetof(struct s, b)); printf("offsetof(struct s, c)=%u\n", offsetof(struct s, c)); printf("offsetof(struct s, d)=%u\n", offsetof(struct s, d[0])); return 0; }
[ZX]