gpt4 book ai didi

haskell - 通过 c2hs 与结构和匿名联合进行交互

转载 作者:行者123 更新时间:2023-12-03 04:50:32 25 4
gpt4 key购买 nike

如何将这一 block C 代码编码到 .chs 文件中,以便 c2hs 可以将其转换为相对较好的内容?

typedef enum {
MONOME_BUTTON_UP = 0x00,
MONOME_BUTTON_DOWN = 0x01,
MONOME_ENCODER_DELTA = 0x02,
MONOME_ENCODER_KEY_UP = 0x03,
MONOME_ENCODER_KEY_DOWN = 0x04,
MONOME_TILT = 0x05,

/* update this if you add event types */
MONOME_EVENT_MAX = 0x06
} monome_event_type_t;

typedef struct monome monome_t; /* opaque data type */
typedef struct monome_event monome_event_t;

typedef void (*monome_event_callback_t)
(const monome_event_t *event, void *data);

struct monome_event {
monome_t *monome;
monome_event_type_t event_type;

/* __extension__ for anonymous unions in gcc */
__extension__ union {
struct {
unsigned int x;
unsigned int y;
} grid;

struct {
unsigned int number;
int delta;
} encoder;

struct {
unsigned int sensor;
int x;
int y;
int z;
} tilt;
};
};

最佳答案

这样怎么样:更改代码以便您命名成员。内存中的布局是相同的,因此它将是二进制兼容的。您必须为该库的每个版本执行此补丁。

struct monome_event {
monome_t *monome;
monome_event_type_t event_type;

/* __extension__ for anonymous unions in gcc */
__extension__ union {
struct me_grid {
unsigned int x;
unsigned int y;
} grid;

struct me_encoder {
unsigned int number;
int delta;
} encoder;

struct me_tilt {
unsigned int sensor;
int x;
int y;
int z;
} tilt;
};
};

关于haskell - 通过 c2hs 与结构和匿名联合进行交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23716996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com