是什么禁用了#pragma pack(push)?
我有一个使用 #pragma pack(push,8) 的代码,但它似乎没有以某种方式生效,但我无法弄清楚是什么导致了这个问题。
例如,看看下面的代码。
#include <windows.h>
#include <stdio.h>
#pragma pack(push, 8)
typedef struct _MY_DATA {
LARGE_INTEGER a;
LARGE_INTEGER b;
ULONG count;
} MY_DATA;
#pragma pack(show)
#pragma pack(pop)
int main()
{
MY_DATA data;
printf("data size:%d\n", sizeof(data));
return 0;
}
这将返回“数据大小:24”,但我在 Visual Studio 管理的其他应用程序中使用相同的代码,并且我得到“数据大小:20”。
所以我假设它与某些设置有关,但无法弄清楚。如果有人能给我一些提示,我将非常感激。谢谢。
I have a code that uses #pragma pack(push,8) but it does not seem to take effect somehow but I can't figure out what's causing this problem.
For example, look at the following code.
#include <windows.h>
#include <stdio.h>
#pragma pack(push, 8)
typedef struct _MY_DATA {
LARGE_INTEGER a;
LARGE_INTEGER b;
ULONG count;
} MY_DATA;
#pragma pack(show)
#pragma pack(pop)
int main()
{
MY_DATA data;
printf("data size:%d\n", sizeof(data));
return 0;
}
This would return "data size:24" but I use the same code in other application that is managed by Visual Studio and there I am getting "data size:20".
So I am assuming it has to do with some settings but could not figure out. I will really appreciate it if anybody could give me some hint. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
项目默认设置的优先级可以高于编译指示 - 请参阅这篇 MSDN 文章。
The project default setting can have higher precedence than the pragma - see this MSDN article.