Re: print struct fields and its member structs' fields recursively, generically
call_me_anything wrote:
I have different kind of data structures in different applications.
The data structures are big and complex and I would like to print the
members of each struct.
Why? How do you want to print them? Are there any pointers in your
structs? How do you intend to print the pointers? Should they be
automatically dereferenced?
Can we write a generic piece of code which will
automatically find out the type of struct elements and
print them (indented manner ?) if they are primitive types like
int, float or char* ? else it will recurse into the composite data
type.
Not that I know of. However, the implementation of the operator<<
is extremely simple.
This is to avoid writing such functions for each struct in each
application.
But usually you don't need to write such functions for _each struct_
in each application. You only need to write those functions for
the structs you *intend to output*.
Sounds something close to gdb ?
With 'gdb' (and other debuggers) there is "debugging information"
that actually doesn't exist in C++ (no such concept is defined).
So, if you want to be OS- or linker-specific, you're welcome to
write your own implementation using the format of the "debugging
information" available.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask