what is the difference between __attribute__((__packed__)); and #pragma pack(1)

前端 未结 1 1170
太阳男子
太阳男子 2021-01-14 07:55

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;         


        
相关标签:
1条回答
  • 2021-01-14 08:32

    __attribute__ is a GCC extension, specific to GCC (and other compilers which attempts to be compatible with GCC).

    #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.

    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.

    0 讨论(0)
提交回复
热议问题