リスト21 リスト22


〔リスト21〕packed属性を指定したソース(test97.c)
#include <stdio.h>
//変数属性の指定 packed  
struct foo
{
    char a;
    int x[2] __attribute__ ((packed));
}foo1;
struct foo_
{
    char a;
    int x[2];
}foo1_;
int main(void)
{
    foo1.a  =   0x00;
    foo1.x[0]   =   0x00;
    printf("foo1のサイズ----%d\n",sizeof(foo1));
    printf("foo1.xのサイズ----%d\n",sizeof(foo1.x));
    printf("foo1_のサイズ----%d\n",sizeof(foo1_));
    printf("foo1_.xのサイズ----%d\n",sizeof(foo1_.x));
    return 0;
}


〔リスト22〕packed属性を指定したソースから生成されたアセンブラ(test97.s)
    .file       "test97.c"
    .version    "01.01"
gcc2_compiled.:
.section    .rodata
.LC0:
    .string "foo1\244\316\245\265\245\244\245\272----%d\n"
.LC1:
    .string "foo1.x\244\316\245\265\245\244\245\272----%d\n"
.LC2:
    .string "foo1_\244\316\245\265\245\244\245\272----%d\n"
.LC3:
    .string "foo1_.x\244\316\245\265\245\244\245\272----%d\n"
.text
    .align  4
.globl  main
    .type   main,@function
main:
    pushl   %ebp
    movl    %esp,%ebp
    subl    $8,%esp
    movb    $0,foo1
    movl    $0,foo1+1
    addl    $-8,%esp
    pushl   $9
    pushl   $.LC0
    call    printf
    addl    $16,%esp
    addl    $-8,%esp
    pushl   $8
    pushl   $.LC1
    call    printf
    addl    $16,%esp
    addl    $-8,%esp
    pushl   $12
    pushl   $.LC2
    call    printf
    addl    $16,%esp
    addl    $-8,%esp
    pushl   $8
    pushl   $.LC3
    call    printf
    addl    $16,%esp
    xorl    %eax,%eax
    jmp .L2
    .p2align    4,,7
.L2:
    movl    %ebp,%esp
    popl    %ebp
    ret
.Lfe1:
    .size   main,.Lfe1-main
    .comm   foo1,9,1
    .comm   foo1_,12,4
    .ident  "GCC: (GNU) 2.95.3 20010315 (release)"