I am currently learning vulkan. In one of the tutorials I saw a function which roughly does the following:
#define SOMESTRING "Hello World!"
std::vector<const char*> buildVector() {
std::vector<const char*> vec;
vec.push_back(SOMESTRING);
return vec;
}
When I saw this, I was wondering: is this defined behavior? Isn't the content of the string "Hello World!"
located on the stack and thus is invalid once the function returns? If this is undefined behavior, what would be the correct way to do this? Unfortunately, using std::string
is not an option because of the vulkan API.
const char* stuff() { return SOMESTRING; }
. The vector doesn't do anything magical here. – Chism