11-25-2020, 11:57 AM
代码:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main()
{
char str[20];
scanf("%s", str);
int32_t x = strtol(str, NULL, 0);
uint32_t u = abs(x); // x=0x80000000 will trigger an undefined behavior
uint64_t val = u;
printf("0x%llx\n", val);
}
输入0x80000000. 在clang -O2,clang -O0,gcc -O0都输出0x80000000. 但是gcc -O2输出0xffffffff80000000.