freakwincy
freakwincy

Reputation: 1267

Is there a C equivalent to Perls' Dumper() method in Data::Dumper?

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.

Upvotes: 2

Views: 881

Answers (2)

Tamas Czinege
Tamas Czinege

Reputation: 121384

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.

Upvotes: 4

Roger Lipscombe
Roger Lipscombe

Reputation: 91885

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.

Upvotes: 2

Related Questions