가능한 중복 :크기
#include <stdio.h> struct employee { int id; char name[30]; }; int main() { struct employee e1; printf("%d %d %d", sizeof(e1.id), sizeof(e1.name), sizeof(e1)); return(0); }
출력은 :
4 30 36
Why isn’t sizeof for a struct equal to the sum of sizeof of each member?
다음 C 코드를 고려
구조체의 크기가 개별 구성 요소 변수의 크기 합계와 같지 않은 이유는 무엇입니까?
당신은 GCC에 포장 속성을 사용할 수 있습니다 ...이 패딩을 드롭하고 가능한 한 작게 구조를 유지한다. struct test_t { int c; } __attribute __ ((__ packed__))); – eaanon01
중복 된 (적어도) http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member – dmckee
eaanon01 . 정말로 정말로 좋은 이유가 있고 모든 함의가 이해되지 않는 한 당신은 포장 된 속성처럼 무언가에 관해서 아무에게도 말하면 안됩니다. –