Is this code UB or not?
__attribute__((const)) const char* foo() {
static const char* str = "yo bro";
return str;
}
__attribute__((pure)) const char* bar() {
static const char* str = "ey mate";
return str;
}
I'm in particular interested in how pure/const work together with the str declaration.
((pure))snippet seems to be well-defined.return "you bro";__attribute__((pure|const))says is that the compiler can remember the return value. Nothing else. You can use__attribute__((const))on evenrand, and then have "interesting" results. But the contents of the function itself do not matter.