With this simple program, the first printf gives back 50, and the second gives back 1. At first we thought it might be caching or optimisation, but no matter what, this is what happens.
#include <stdio.h>
#include <string.h>
int compare (void const * a, void const * b) {
return strcmp((char const *) a, (char const *) b);
}
int main(void) {
printf("%i\n", compare((void const *) "Key2", (void const *) "Key")); // 50
printf("%i\n", strcmp("Key2", "Key")); // 1
return 0;
}
In comparison, https://repl.it/CZ5h/2 shows that both give back 1. But my GCC is 5.3.0.
So what is the reason for the results being different?
Also noticed that clang compiles a program that gives deterministic results.