小编Kil*_*All的帖子

Different behavior when I running a program compiled with G ++ in Docker

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)

c++ g++ compiler-optimization docker

2
推荐指数
1
解决办法
43
查看次数

标签 统计

c++ ×1

compiler-optimization ×1

docker ×1

g++ ×1