Re: C/C++ header file parser

"Michael Tiomkin" <>
3 Oct 2006 18:17:34 -0400

          From comp.compilers

Related articles
C/C++ header file parser (Pankaj Garg) (2006-09-30)
Re: C/C++ header file parser (2006-10-03)
Re: C/C++ header file parser (Pascal Bourguignon) (2006-10-03)
Re: C/C++ header file parser (Alex McDonald) (2006-10-03)
Re: C/C++ header file parser (Paul Pluzhnikov) (2006-10-03)
Re: C/C++ header file parser (Michael Tiomkin) (2006-10-03)
Re: C/C++ header file parser (Ira Baxter) (2006-10-10)
| List of all articles for this month |

From: "Michael Tiomkin" <>
Newsgroups: comp.compilers
Date: 3 Oct 2006 18:17:34 -0400
Organization: Compilers Central
References: 06-09-169
Keywords: C++, parse
Posted-Date: 03 Oct 2006 18:17:34 EDT

Pankaj Garg wrote:
> I need to parse C/C++ header files and extract information about data
> types, functions and function arguments. Which tools/libraries would
> be suitable for me? Are there any examples/sample programs for such.
> I don't want to build a full fledged yacc based parser so i am looking
> for a ready made parser, preferably open source.

    All the compilers use the type info in order to create the debug
info part of the compiled object. Unfortunately, if the type is not
used, they ignore it. You can take gcc and force it to save the type
info of unused types. Then you can compile any header file and read
its debug info. The only problem would be the C++ templates, because
they usually are not a part of debug info. You can save the precompied
templates somewhere and read them later. Recall that you should run
the compiler with the same options that you use in the project,
because this influences the macro language, struct alignment etc.

    A "dirtier" solution can be changing ctags to include the
declarations instead of definitions. ctags has a much simpler parser,
however I'm not sure if the modern ctags can parse C++ files.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.