views:

62

answers:

2

Essentially, what I'm looking for is a function that would allow me to do something like this:

Dumper(some_obj); /* outputs some_objs' data structure */

Thanks.

+1  A: 

Short answer: no.

Long answer: by the time your program's been compiled and linked, all of that information has been thrown away. C (and C++) don't have reflection, so none of this information can be recovered at runtime.

Intriguing answer: Since you're on Windows, you can do various things with debug information (i.e. PDB files) and the DbgHelp API.

Roger Lipscombe
Thanks for the clarification Roger. The code I'm actually working on is a modified version of the RIPE WHOIS server and though I'm on Windows, most of my work actually gets done in Linux (via SSH). Perhaps I'll try building the source locally and seeing if I can get it running in debug mode in Visual Studio Express.
freakwincy
+1  A: 

C doesn't support any kind of reflection out of the box. Also it's not hard typed in the sense that once it's compiled to machine code, types aren't there any more (unlike in some higher level languages). You need to build your executable with all the symbols and debug info and then use some debugging tool or library to retrieve this data.

I suppose just using an estabilished debugger such as the Visual Studio Debugger or gdb would be much simpler.

DrJokepu
Thank you very much for the explanation. I think I'll give the Visual Studio Debugger a whirl as I'm not too familiar with gdb- tried debugging the code with it a little earlier, albeit unsuccessfully.
freakwincy