Rss & SiteMap

曙海教育集團(tuán)論壇 http://www.bjzhda.cn

曙海教育集團(tuán)論壇
共1 條記錄, 每頁顯示 10 條, 頁簽: [1]
[瀏覽完整版]

標(biāo)題:各位對C語言結(jié)構(gòu)中成員的對齊(alignment)怎樣理解?

1樓
wangxinxin 發(fā)表于:2010-12-10 11:47:29
本來覺得自已很清楚了,后來看到一個(gè)例子,又糊涂了。先看一個(gè)WATCOM給出的表:(ZP1表示按一個(gè)字符對齊) zp1 zp2 zp4 zp8 zp16 sizeof(member) \--------------------------------------- 1 | 0 0 0 0 0 2 | 0 2 2 2 2 4 | 0 2 4 4 4 8 | 0 2 4 8 8 16 | 0 2 4 8 16 x | aligned to largest member 看一段代碼: #include #include typedef struct memo_el { char date[9]; struct memo_el *prev,*next; int ref_number; char sex; } memo; main( ) { printf( "Offset of %s is %d\n", "date", offsetof( memo, date ) ); printf( "Offset of %s is %d\n", "prev", offsetof( memo, prev ) ); printf( "Offset of %s is %d\n", "next", offsetof( memo, next ) ); printf( "Offset of %s is %d\n", "ref_number", offsetof( memo, ref_number ) ); printf( "Offset of %s is %d\n", "sex", offsetof( memo, sex ) ); printf( "Size of %s is %d\n", "memo", sizeof( memo ) ); printf( "Number of padding bytes is %d\n", sizeof( memo ) - (offsetof( memo, sex ) + sizeof( char )) ); return 0; } 輸出: 16位zp1:(毫無疑問) Offset of date is 0 Offset of prev is 9 Offset of next is 11 Offset of ref_number is 13 Offset of sex is 15 Size of memo is 16 Number of padding bytes is 0 16位 zp2、4、8結(jié)果都一樣: Offset of date is 0 Offset of prev is 10 Offset of next is 12 Offset of ref_number is 14 Offset of sex is 16 Size of memo is 18 Number of padding bytes is 1 如果再把成員改一個(gè)長整類型, typedef struct memo_el { char date[9]; struct memo_el *prev,*next; long int ref_number; char sex; } memo; 結(jié)果在16位ZP2-8都是這樣: Offset of date is 0 Offset of prev is 10 Offset of next is 12 Offset of ref_number is 16 Offset of sex is 20 Size of memo is 24 Number of padding bytes is 3 現(xiàn)在我無法解釋了~
共1 條記錄, 每頁顯示 10 條, 頁簽: [1]

Copyright © 2000 - 2009 曙海教育集團(tuán)
Powered By 曙海教育集團(tuán) Version 2.2
Processed in .01563 s, 2 queries.
主站蜘蛛池模板: 好男人社区在线www| 女律师的堕落高清hd| 亚洲欧美中文日韩在线v日本| 麻豆高清免费国产一区| 天天操天天干天天| 久久亚洲AV成人无码国产| 熟妇人妻va精品中文字幕| 国产人与zoxxxx另类| 91精品国产色综合久久不| 我把护士日出水了| 亚洲一区二区三区欧美| 男高中生大粗吊gvlive| 国产亚洲精品bt天堂精选 | 又粗又硬又黄又爽的免费视频| 在线免费观看h| 女老丝袜脚摩擦阳茎视频| 久久免费区一区二区三波多野| 欧美最猛性xxxx| 免费国产小视频在线观看| 青草国产精品久久久久久| 国产精品毛多多水多| www.好吊妞| 无遮无挡爽爽免费视频| 亚洲国产aⅴ成人精品无吗| 男人使劲躁爽女人动态图| 国产v片成人影院在线观看| 欧美激情成人网| 国产麻豆91网在线看| 一区在线观看视频| 日本www视频| 五月婷婷亚洲综合| 欧美精品福利在线视频| 免费看无码特级毛片| 被催眠暴jian的冷艳美mtxt下载| 国产精品99久久久久久猫咪| 99久热只有精品视频免费观看17| 成人永久福利在线观看不卡| 久久福利一区二区| 欧美videosex性欧美成人| 亚洲精品网站在线观看你懂的| 精品国产一区二区三区2021|