Converting a Variable Name to/from a String Representation

Tom Browder tom3@fwb.asi.srs.com
Wed Jun 11 15:24:00 GMT 2003


In C++ we can initialize a char* vector (array) like so:

  char* vec[] = { "s1", "s2" };

Is there any equivalent way to do it for a C++ vector?  I don’t think
so--except by constructing a std::vector<std::string> from the char* array
at runtime.

So the question is: wouldn't that be a "good thing" for a C++ extension to
g++?  It would continue the move away from the "dangerous" C string and it
would conserve space since we wouldn't need two copies of the array (or does
g++ do some behind-the-scenes optimizations?).  My idea of such an
initialization is:

  std::vector<std::string> vec = { "s1, "s2 };

Thanks.

Tom Browder
I would like to convert a string representation of a variable into the
variable name as the program knows it, or, conversely, get the string
representation of a variable's name.

gcc has a way to get a calling function's name, is there any way to do
something similar with a variable name?

Thanks.

Tom Browder




More information about the Gcc-help mailing list