-3

I have many structures, which looks like:

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));

Number of members, their names, type and size of bit fields are different. I need create this structures according to data from 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>

How can I do this?

Gusya
  • 1
  • 1
  • Do you what to create C source code based on this XML file or do you want to somehow create these structures in run-time in the same program that's reading the XML? It would be better if you mentioned what do you need this for. – r3mus n0x Mar 15 '19 at 20:24
  • I need to be able add or change structures without a recompile of the project – Gusya Mar 15 '19 at 22:03
  • What exactly are you doing with those structures in your project? – r3mus n0x Mar 15 '19 at 22:04
  • I send them via udp – Gusya Mar 15 '19 at 22:09

1 Answers1

0

Out of topic, but you can thing about using a library such as cTemplate to generate your code, and a XML Parser.

Next time try : https://softwarerecs.stackexchange.com/

willll
  • 1,809
  • 1
  • 16
  • 23