本文主要是介绍gcc对于大数的溢出截断,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
gcc编译器对于大整数常数的溢出截断操作,视为此大整数在更大类型上的补码截断为当前类型。
test.c
void test()
{
unsigned char a=257;
char b=-129;
char c=130;
char d=255;
}
D:\>gcc -S test.c -o test.s > test.txt
test.c: 在函数‘test’中:
test.c:3:2: 警告:大整数隐式截断为无符号类型 [-Woverflow]
test.c:4:2: 警告:隐式常量转换溢出 [-Woverflow]
test.s
subl $16, %esp
movb $1, -1(%ebp)
movb $127, -2(%ebp)
movb $-126, -3(%ebp)
movb $-1, -4(%ebp)
test.obj反汇编
D:\>objdump test.obj -D
test.obj: file format pe-i386
Disassembly of section .text:
00000000 <.text>:
0: 83 ec 10 sub $0x10,%esp
3: c6 45 ff 01 movb $0x1,-0x1(%ebp)
7: c6 45 fe 7f movb $0x7f,-0x2(%ebp)
b: c6 45 fd 82 movb $0x82,-0x3(%ebp)
f: c6 45 fc ff movb $0xff,-0x4(%ebp)
13: 90 nop
D:\>
这篇关于gcc对于大数的溢出截断的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!