[lug] C++ question, without buying expensive doc.s

Tom Tromey tromey at redhat.com
Tue Jan 11 14:45:19 MST 2005


>>>>> "Tkil" == Tkil  <tkil at scrye.com> writes:

Paul> It's not being a language lawyer. Serialize/deserialize really
Paul> needs a linkage (_not_ in the compiler technical sense) from an
Paul> object back to its text name, otherwise such linkage must be
Paul> hand crafted for each individual object that is to be
Paul> serialized.

Tkil> Huh.  In my very limited exposure to environments that try to do
Tkil> serialization "automagically" in C++, I was never very happy with the
Tkil> results.

Tkil> I wonder what Tom Tromey has to say about it...

I was called, but I'm afraid I don't have much useful to say.

You might have a struggle getting C++ class names out of something
like __FUNCTION__.  Does __FUNCTION__ change value depending on a
particular template instantiation?  I'm not sure.

I've heard of folks doing serialization by reading debug info
describing their structures, then generating code from that.  This is
pretty involved, I think they had to hack binutils to get at the info.
Perhaps there's a libdwarf out there somewhere.

GCC itself does some serializing to implement precompiled headers and
its garbage collector.  This involves annotating the sources with a
special macro (look for "GTY") and then having another program that
scans the sources and generates code to mark structures and the like.

I suppose if I had to do this these days, I would try to modify g++ to
generate the information I needed.  There's been a little talk about
this on the GCC list lately.


BTW, fun trick: in the old days folks used to find the list of
symbols that a compiler predefined by using "strings" on  the
executable, then transforming the result into something like:

    #ifdef foo
      printf("foo\n");
    #endif

Then you compile this with the compiler and it will tell you what the
compiler defined.

Tom



More information about the LUG mailing list