如何在Linux中将以下vc++打包命令转换为gcc命令?我知道如何针对单个结构执行此操作,但是如何针对一系列结构执行此操作?
#pragma pack(push, 1) // exact fit - no padding
//structures here
#pragma pack(pop) //back to whatever the previous packing mode was
最佳答案
您可以将属性((打包))添加到各个数据项中以实现此目的。在这种情况下,打包将应用于数据项,因此无需还原旧模式。
例如:
对于结构:
typedef struct _MY_STRUCT
{
}__attribute__((packed)) MY_STRUCT;
对于数据成员:
struct MyStruct {
char c;
int myInt1 __attribute__ ((packed));
char b;
int myInt2 __attribute__ ((packed));
};
关于c++ - 如何将结构打包从vc++转换为gcc,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13927273/