I am curious about the liberties that a compiler has when optimizing. Let\'s limit this question to GCC and C/C++ (any version, any flavour of standard):
Is it possi
a.c:
char *f1(void) { return "hello"; }
b.c:
#include
char *f1(void);
int main()
{
if (f1() == "hello") printf("yes\n");
else printf("no\n");
}
Output depends on whether merge string constants optimization is enabled or disabled:
$ gcc a.c b.c -o a -fno-merge-constants; ./a
no
$ gcc a.c b.c -o a -fmerge-constants; ./a
yes