views:

198

answers:

1

Hi,

Is it possible to get Visual Studio to output any of the type information when compiling C++? GCC has GCC-XML and I was wondering there was something similar for VS2008.

Thanks

BEN

+2  A: 

There are a number of solutions to this problem;

  1. there is of course, the XML documentation.
  2. You can enable the attributed source output under "C/C++" -> Output Files, "Expand Attributed Source" and also various levels of Assembler Output listings.

    Unfortunately, those methods are fairly laborious and unstructured (i.e. manual cracking of syntax).

  3. RTTI is enabled by-default for all C/C++ projects. This being the fore-runner of C#'s reflection, you can use it to extract very well structured and accurate information.
  4. Name Mangling, can be present even when RTTI is not available. C++ binaries may rely on this packed-formulation of the original code deceleration to enable runtime polymorphism's or other oo'ness templeate'd feature ;). Anyhow, even though name mangling is not well documented, there exists an API call in the debug SDK and actually even in the Windows Win32 APi, which will "un decorate" the mangled representation for you. You may then still have to convert the un-decorated format, in any case, it's fairly trivial at that point.
  5. PDB files, you can use the DIA SDK to interrogate PDB's which you compiled. There are several level's of verbosity (public vs. private) in the information contained in PDB's but it's usually more than enough.
  6. Look at the new-gen compiler, Phoenix, from MSR, it has impressive binary/source introspective capabilities.
  7. CodeDom, you can use the MSVC SDK and domain specific language (DSL) libraries to write your own code parser fairly easily.
  8. There are actually several other automation and non-DSL API's in MSVC you can use to accomplish something, maybe not as comprehensive, but that depends on your needs. Anyhow, most of the examples and info you can find about these other API's would be written in BASIC, so unless you know VB (I really get stumped every time I have to look at VB code), your millage may vary.
  9. I could go on.... ;) but I'm fine with 9.
RandomNickName42
Ben: Failing RTTI, what other constraints's are you working with? Did you try the DIA SDK? Dia2dump.c comes with visual studio.
RandomNickName42
I'm still investigating all these options (thanks for so many fantastic ideas!).
Ben
Ben: Check out this recently released mingw project."MinGW: A native Windows port of the GNU Compiler Collection (GCC), with freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. "The Source Navigator development team has released a Windows compatible MinGW compilable version it has dubbed NG4. http://developer.berlios.de/project/showfiles.php?group_id=8334. It may have better compatabiltiy to windows headers than gccxml port's do.
RandomNickName42