小编Efr*_*iss的帖子

GCC优化了一个无法优化的if子句

我创建了一个小代码,显示我遇到的错误

#include<stdlib.h>
#include<stdio.h>
int test(char * flag)
{
    char flagger = *flag;
    printf("test value %d", (int) flagger);
    if (flagger != 0x82)
    {
        exit(3);
    }
    else 
    {
        return 0;
    }
}


int main(void)
{
    char flag = 0x82, flag1 = 0x12, flag2 = 0x45;
    //char buf[256];
    test(&flag);
    test(&flag1);
    test(&flag2);
}
Run Code Online (Sandbox Code Playgroud)

编译代码时:gcc -o tester test.c或gcc -o tester test.c -O0

The resulting disassembly code for the function test in gdb is:  
Dump of assembler code for function test:
0x0804849b <+0>:    push   ebp
0x0804849c …
Run Code Online (Sandbox Code Playgroud)

c gcc compiler-optimization

3
推荐指数
1
解决办法
97
查看次数

标签 统计

c ×1

compiler-optimization ×1

gcc ×1