title: Extract the fields of a C struct
body: <p>I often have to write code in other languages that interact with C structs.  Most typically this involves writing Python code with the <a href="http://docs.python.org/library/struct.html" rel="noreferrer">struct</a> or <a href="http://docs.python.org/library/ctypes.html" rel="noreferrer">ctypes</a> modules.</p>
  
  <p>So I'll have a .h file full of struct definitions, and I have to manually read through them and duplicate those definitions in my Python code.  This is time consuming and error-prone, and it's difficult to keep the two definitions in sync when they change frequently.</p>
  
  <p>Is there some tool or library in any language (doesn't have to be C or Python) which can take a .h file and produce a structured list of its structs and their fields?  I'd love to be able to write a script to generate my automatically generate my struct definitions in Python, and I don't want to have to process arbitrary C code to do it.  Regular expressions would work great about 90% of the time and then cause endless headaches for the remaining 10%.</p>