__attribute __((__ packed__))有什么区别;和#pragma pack(1) [英] what is the difference between __attribute__((__packed__)); and #pragma pack(1)
问题描述
我正在将在Linux上完美运行的代码移植到Windows visual c ++.我在Linux中有以下代码:
I am porting a code which runs perfectly on Linux to windows visual c++. I have this code in Linux:
struct exif_desc
{
uint16_t tag;
uint16_t type;
uint32_t length;
uint32_t value;
}
__attribute__((__packed__));
我在Windows上遇到错误:
I am getting error on windows:
'__packed__' : undeclared identifier
我想知道是否可以使用
#pragma pack(1)
它们之间有什么区别吗?在Linux和Windows中是否可以为此属性使用任何语法?
is there any difference between them? Is there any syntax that can be used in Linux and Windows for this attribute?
推荐答案
__ attribute __
是GCC扩展,特定于GCC(以及其他尝试与GCC兼容的编译器).
__attribute__
is a GCC extension, specific to GCC (and other compilers which attempts to be compatible with GCC).
#pragma pack
最初是Visual C ++编译器特定的扩展.如评论者所述,它也已在GCC中实现,以实现VC ++兼容性.
#pragma pack
is originally a Visual C++ compiler specific extension. It has, as noted by commenters, been implemented in GCC as well for VC++ compatibility.
通常,您不能在另一个编译器中的一个编译器中使用扩展名.恰当的例子: __ attribute __
在Visual C ++编译器中不作为扩展名存在.
Normally you can't use extensions in one compiler in another compiler. Case in point: __attribute__
doesn't exist as an extension in the Visual C++ compiler.
这篇关于__attribute __((__ packed__))有什么区别;和#pragma pack(1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!