"Hello, World" not of type const char* . It is of type const char[13] and this value is an lvalue, not an rvalue.
When you use "Hello, World" in a context in which it is implicitly converted to const char* pointing to its source element, the resulting pointer is an rvalue (since this is a temporary object that is the result of an implicit conversion.
For example, in GCC 4.5.2, a method that returns an int as opposed to int& is considered to return an int&& .
If you call a function that returns a value (for example, int ), then this function expression expresses the rvalue expression. If you call a function that returns an lvalue reference (for example, int& ), then this function expression expresses the lvalue expression.
How to distinguish a variable as a string built by the compiler?
You cannot, really: there is no difference between "Hello, World" and any other const char[13] that you could declare.
As for storing const char* or any other types of pointers in a standard library container, for example std::vector , the container will not touch the specified data: the container is only going to create, move, copy, and destroy pointers.
If you need to manage the specified data, you need to do it yourself by writing a class to manage the object with a pointer (like a class of smart pointers). The idiom of writing a class to manage a resource like this is called Resource Initialization (RAII) or Limited to Resource Management Area (SBRM).
James McNellis Mar 18 '11 at 0:40 2011-03-18 00:40
source share