<legend id='RKLAo'><style id='RKLAo'><dir id='RKLAo'><q id='RKLAo'></q></dir></style></legend>
    <tfoot id='RKLAo'></tfoot>

    <i id='RKLAo'><tr id='RKLAo'><dt id='RKLAo'><q id='RKLAo'><span id='RKLAo'><b id='RKLAo'><form id='RKLAo'><ins id='RKLAo'></ins><ul id='RKLAo'></ul><sub id='RKLAo'></sub></form><legend id='RKLAo'></legend><bdo id='RKLAo'><pre id='RKLAo'><center id='RKLAo'></center></pre></bdo></b><th id='RKLAo'></th></span></q></dt></tr></i><div id='RKLAo'><tfoot id='RKLAo'></tfoot><dl id='RKLAo'><fieldset id='RKLAo'></fieldset></dl></div>

    <small id='RKLAo'></small><noframes id='RKLAo'>

    • <bdo id='RKLAo'></bdo><ul id='RKLAo'></ul>
      1. struct sizeof 结果不是预期的

        时间:2023-07-01
          <tbody id='7VrRC'></tbody>
          <bdo id='7VrRC'></bdo><ul id='7VrRC'></ul>

          1. <small id='7VrRC'></small><noframes id='7VrRC'>

              <i id='7VrRC'><tr id='7VrRC'><dt id='7VrRC'><q id='7VrRC'><span id='7VrRC'><b id='7VrRC'><form id='7VrRC'><ins id='7VrRC'></ins><ul id='7VrRC'></ul><sub id='7VrRC'></sub></form><legend id='7VrRC'></legend><bdo id='7VrRC'><pre id='7VrRC'><center id='7VrRC'></center></pre></bdo></b><th id='7VrRC'></th></span></q></dt></tr></i><div id='7VrRC'><tfoot id='7VrRC'></tfoot><dl id='7VrRC'><fieldset id='7VrRC'></fieldset></dl></div>

              • <legend id='7VrRC'><style id='7VrRC'><dir id='7VrRC'><q id='7VrRC'></q></dir></style></legend>
                • <tfoot id='7VrRC'></tfoot>
                  本文介绍了struct sizeof 结果不是预期的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个这样定义的结构:

                  I have a a struct defined thusly:

                  typedef struct _CONFIGURATION_DATA {
                      BYTE configurationIndicator;
                      ULONG32 baudRate;
                      BYTE stopBits;
                      BYTE parity;
                      BYTE wordLength;
                      BYTE flowControl;
                      BYTE padding;
                  } CONFIGURATION_DATA;
                  

                  现在,据我估计,该结构体有 10 个字节长.但是,sizeof 报告它是 16 字节长?有人知道为什么吗?

                  Now, by my reckoning, that struct is 10 bytes long. However, sizeof reports that it is 16 bytes long? Anyone know why?

                  我正在使用 Windows DDK 中的构建工具进行编译.

                  I am compiling using the build tools in the Windows DDK.

                  推荐答案

                  对齐.

                  使用

                  #pragma pack(1)

                  ...结构在这里...

                  #pragma pack()

                  我还建议重新排序,如果有必要填充,然后使用 RESERVED 字节,以便多字节整数类型更好地对齐.这将使 tbe CPU 的处理速度更快,并且您的代码更小.

                  I would also recommend reordering things, and if necessary padding then with RESERVED bytes, so that multi-byte integral types will be better aligned. This will make processing faster for tbe CPU, and your code smaller.

                  这篇关于struct sizeof 结果不是预期的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C 与 C++ 中的 struct 和 typedef 下一篇:如何更改 Directshow 过滤器属性 C++

                  相关文章

                  <tfoot id='z87hr'></tfoot>

                  <small id='z87hr'></small><noframes id='z87hr'>

                    <legend id='z87hr'><style id='z87hr'><dir id='z87hr'><q id='z87hr'></q></dir></style></legend>
                      • <bdo id='z87hr'></bdo><ul id='z87hr'></ul>
                      <i id='z87hr'><tr id='z87hr'><dt id='z87hr'><q id='z87hr'><span id='z87hr'><b id='z87hr'><form id='z87hr'><ins id='z87hr'></ins><ul id='z87hr'></ul><sub id='z87hr'></sub></form><legend id='z87hr'></legend><bdo id='z87hr'><pre id='z87hr'><center id='z87hr'></center></pre></bdo></b><th id='z87hr'></th></span></q></dt></tr></i><div id='z87hr'><tfoot id='z87hr'></tfoot><dl id='z87hr'><fieldset id='z87hr'></fieldset></dl></div>