Oli*_*_Mo 5 c++ struct c++-cli
我的问题是指标题中提到的问题.
我在头文件中有一个简单的结构,如下所示:
typedef struct
{
WORD FileType; // File ID (0x7000)
WORD HeaderSize; // Size of this file header in Bytes
WORD HeaderVersion; // yy.y
ULONG FileSize; // Size of the whole file in Bytes
WORD ImageHeaderSize; // Size of the image header in Bytes
WORD ULX, ULY, BRX, BRY;// bounding rectangle of the image
WORD NrOfFrames; // self explanatory
WORD Correction; // 0 = none, 1 = offset, 2 = gain, 4 = bad pixel, (ored)
double IntegrationTime; // frame time in microseconds
WORD TypeOfNumbers; // short, long integer, float, signed/unsigned, inverted,
// fault map, offset/gain correction data, badpixel correction data
BYTE x[WINRESTSIZE]; // fill up to 68 byte
} WinHeaderType;
Run Code Online (Sandbox Code Playgroud)
如果我在C控制台应用程序中调用sizeof(WinHeaderType),我得到68,但如果我在C++/CLI中使用相同的参数调用相同的函数,我得到80.
有人可以向我解释这种行为吗?
我对C++/CLI很陌生,事实上我之前从未使用它(几天前开始),但我需要为.NET应用程序创建一个dll.
由于这是我的第一篇文章,我希望我没有违反任何论坛规则.
格力兹,莫
[编辑]它变得陌生和陌生......

第一行:C控制台应用程序输出
第二行,第一列:C/C++控制台应用程序我编码以检查数据类型大小.
第二行,第二列:C++/CLI控制台应用程序我编码以检查DataType大小.
第一个应用程序的来源:http://fbe.am/sId
最近两个应用程序的项目文件:http://fbe.am/sIf
有人解释这个吗?!
使用默认打包规则 (/Zp8),结构包含 12 字节的填充以使成员对齐。这应该足以解释 68 和 80 之间的区别。您必须消除填充,#pragma pack在 MSVC 编译器中使用:
#pragma pack(push, 1)
typedef struct {
// .. etc
} WinHeaderType;
#pragma pack(pop)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
441 次 |
| 最近记录: |