小编use*_*582的帖子

在Borland C++上使用#pragma pack和#define

我试图用Borland C++ Builder(XE6)打包一些结构(将来:bcc).

我使用的库使用以下构造来创建结构:

#ifdef _MSC_VER
    #define PACKED_BEGIN __pragma(pack(push, 1))
    #define PACKED 
    #define PACKED_END __pragma(pack(pop))
#elif defined(__GNUC__)
    #define PACKED_BEGIN
    #define PACKED  __attribute__((__packed__))
    #define PACKED_END
#endif


PACKED_BEGIN
struct PACKED {
    short someSampleShort;
    char sampleByte;
    int sampleInteger;
} structType_t;
PACKED_END
Run Code Online (Sandbox Code Playgroud)

bcc编译器不喜欢MSC __pragma,并且不喜欢宏内部的预处理器指令,尽管它们在他们的网站上有描述:

#define GETSTD #include <stdio.h>
Run Code Online (Sandbox Code Playgroud)

我的问题是:是否有可能在Borland编译器中使用此构造来打包结构而不使用:

#pragma pack(1) 
Run Code Online (Sandbox Code Playgroud)

打包每个结构?

这有什么变通方法吗?

c++ c++builder pragma borland-c++

5
推荐指数
1
解决办法
2593
查看次数

标签 统计

borland-c++ ×1

c++ ×1

c++builder ×1

pragma ×1