来自数组的成员和比特菲尔德的结构

Structures with variable number of members and bitfields from the array

本文关键字:菲尔德 结构 成员 数组      更新时间:2023-10-16

我有许多结构,看起来像:

struct S {
float a;
uint8_t b;
uint8_t c : 4; 
uint8_t d : 2; 
uint8_t e : 1; 
uint8_t f : 1; 
uint8_t g : 1;
...
} __attribute__((packed));

成员数,其名称,类型和大小的位字段不同。我需要根据XML的数据创建此结构。

<S>
<a type="float", size=""/>
<a type="uint8_t", size=""/>
<a type="uint8_t", size="4"/>
<a type="uint8_t", size="2"/>
<a type="uint8_t", size="1"/>
<a type="uint8_t", size="1"/>
<a type="uint8_t", size="1"/>
</S>

我该怎么做?

否则主题,但是您可以使用诸如ctemplate之类的库生成代码和XML解析器。

下次尝试:https://softwarerecs.stackexchange.com/