具有可变数量的成员和阵列中的位域的结构

问题描述 投票:-3回答:1

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

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>

我怎样才能做到这一点?

c++ templates struct bit-fields
1个回答
0
投票

超出主题,但您可以使用cTemplate等库来生成代码和XML Parser

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

© www.soinside.com 2019 - 2024. All rights reserved.