The behavior of the executable is different if it is run inside the docker, or on the host. But this only happens when we change the optimization level of G++.
Compiler: g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
我正在尝试执行以下代码:
#include <cstdio>
#include <cstring>
int main()
{
int nOrd =3395;
char cOrd[] = "003395";
char cAux2[256];
strcpy(cAux2, cOrd);
int nRest = nOrd % 26;
printf("BEFORE SPRINTF %s\n\n\n", cAux2);
sprintf(cAux2, "%s%c", cAux2, (nRest+65));
printf("AFTER SPRINTF %s\n\n\n", cAux2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我编译:
g++ -o FastCompile FastCompile.c …Run Code Online (Sandbox Code Playgroud)