【发布时间】:2019-02-10 04:20:10
【问题描述】:
我正在将 C 库转换为 Delphi。 我在转换下面的代码时遇到问题。 这是用于通信的结构,所以顺序必须正确。
德尔福
Tparam_union_params_t = packed record
case Integer of
0: (param_float:single);
1: (param_int32:Int32);
2: (param_uint32:UInt32);
...
...
end;
Tparam_union_t = packed record
param:Tparam_union_params_t // This method requires var name.
type:UInt8;
end;
C 朗
#ifdef __GNUC__
#define PACKED( __Declaration__ ) __Declaration__ __attribute__((packed))
#else
#define PACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
#endif
PACKED(
typedef struct param_union {
union {
float param_float;
int32_t param_int32;
uint32_t param_uint32;
int16_t param_int16;
uint16_t param_uint16;
int8_t param_int8;
uint8_t param_uint8;
uint8_t bytes[4];
}; // This no-named union. no-named is important.
uint8_t type;
}) param_union_t;
我的方法需要 var name 但是原始的c代码是无名的。 如何将 C 中的匿名联合或结构转换为 Delphi?
【问题讨论】: