zoukankan      html  css  js  c++  java
  • C166 结构按字节访问的设置

    PACK Compiler Directive

    Abbreviation

    None.

    Arguments

    A decimal number (1 or 2) enclosed in parentheses.

    Default

    PACK(1)

    µVision

    Options — C166 â€” Misc Controls.

    Description

    The PACK directive causes the compiler to generate byte-aligned or half-word-aligned structures. This is useful when exchanging data with other systems where no alignment is required.

     Note

    • The compiler generates considerably more code to access byte-aligned words. For this reason, PACK(1)should be used only when necessary.
    • By default, the compiler assumes that structure members are aligned on word boundaries. If you use PACK(1) some structure members may be aligned on byte boundaries. The BYTEALIGN directive supports pointers to structure members that are aligned on byte boundaries.
    See Also

    BYTEALIGN

    Example
    #pragma pack(1)     /* byte alignment */
    #pragma bytealign   /* ptrs to byte-aligned objects */
    
    struct s1  {
      int  i1;     // i1 has offset 0
      char c1;     // c1 has offset 2
      int  i2;     // i2 has offset 3
      char c2;     // c2 has offset 5
      int  i3;     // i3 has offset 6
      char z1;     // z1 has offset 8
    };
    
    #pragma pack()    /* reset to default alignment */
    
    struct s2  {
      int  i1;     // i1 has offset 0
      char c1;     // c1 has offset 2
      int  i2;     // i2 has offset 4
      char c2;     // c2 has offset 6
      int  i3;     // i3 has offset 8
      char z1;     // z1 has offset 10
    };
    

     Related Knowledgebase Articles

  • 相关阅读:

    使用docker构建fastdfs
    docker测试
    java测试远程调试(转载)
    mac上运行mongodb-community
    mac上zookeeper服务开启,kafka开启
    idea注册配置
    java-集合
    selenium+phantomjs爬取bilibili
    [转载] Python数据类型知识点全解
  • 原文地址:https://www.cnblogs.com/xihong2014/p/10085134.html
Copyright © 2011-2022 走看看