【问题标题】:How do we force compiler not to have structure padding? Please explain我们如何强制编译器没有结构填充?请解释
【发布时间】:2016-01-10 06:48:50
【问题描述】:

我们如何强制编译器没有结构填充?请解释一下。

【问题讨论】:

标签: c


【解决方案1】:

What is a "packed" structure in C? 的帖子介绍了如何在使用 gcc 时避免填充。

struct foo __attribute__((__packed__)) 
{
   ...
};

clang 的方法相同。见How to declare packed struct (without padding) for LLVM?

Locally disable padding 的帖子介绍了如何在使用 MS Visual Studio 时避免填充。

#pragma pack(push, 1)
struct foo
{ 
   ...
};
#pragma pack(pop)

【讨论】:

    猜你喜欢
    • 2016-12-28
    • 2014-05-22
    • 2015-07-02
    • 2020-11-27
    • 2012-03-30
    • 2019-07-08
    • 2022-11-27
    • 2019-03-22
    • 1970-01-01
    相关资源
    最近更新 更多