beiyu95的专栏

关注测试技术的个人空间

北玉ID:beiyu95
10565次访问,排名9933(-1)好友0人,关注者4
beiyu95的文章
原创 9 篇
翻译 0 篇
转载 11 篇
评论 24 篇
beiyu95的公告
本人Blog上可能收藏和参考了一些有知识产权的东西,如果你认为我的行为侵犯了您的知识产权或其他权益,请联系本人,本人即刻修改。联系方式:beiyu95@163.com
最近评论
文章分类
收藏
    相册
    精彩无限
    技术站点
    www.theseverside.com
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 Basic concepts of pragma pack and alignment 收藏

     | 旧一篇: sizeof and alignment

    I have see several knowledge article about this topic. The rules is not very complicated. But maybe there are several concepts should be clarified. If we understand them clearly, this topic is so easy.
    1) alignment  is  processed in  compile-time;
        By the way, sizeof is also be processed in compile-time just like array length is determined at compile-time.
    2) if you have assigned a value n to pragma pack directive, e.g. #pragma pack(n), the compiles will  compare the value n with the minimal size of the struct and choose the less one.
    e.g.
    struct struct1{
         char a;
         int b;
         double c;
         char*p;
    };

    default sizeof(struct1) is 20;
    for pack(1), the value is 17;
    for pack(2), the value is 18;
    for pack(4), the value is 20;
    for pack(8), the value still is 20!

    I have test it with GCC 4.1.2.

    发表于 @ 2008年04月06日 11:18:00|评论(loading...)|编辑

     | 旧一篇: sizeof and alignment

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © beiyu95