This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Converting a Variable Name to/from a String Representation
- From: "Tom Browder" <tom3 at fwb dot asi dot srs dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Wed, 11 Jun 2003 10:30:21 -0500
- Subject: Converting a Variable Name to/from a String Representation
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