Why gdb cast output truncated once input exceed int max?

0

Example of p/x:

(gdb)  p/x (long long)-2147483647 #still works
$1 = 0xffffffff80000001
(gdb) p/x (long long)-2147483648 #truncated once input exceed max int
$2 = 0x80000000
(gdb) p/x (long long)-2147483649
$3 = 0x7fffffff
(gdb) whatis $1
type = long long
(gdb) whatis $2
type = long long
(gdb) whatis $3
type = long long

And p/u:

(gdb) p/u (long long)-2147483647
$1 = 18446744071562067969
(gdb) p/u (long long)-2147483648
$2 = 2147483648
(gdb) whatis $1
type = long long
(gdb) whatis $2
type = long long

I always concluded that this is gdb bug, but now I think I may misunderstanding and decided to post this question here.

Output (as requested by comment):

(gdb) whatis -2147483647
type = int
(gdb) whatis -2147483648
type = unsigned int
(gdb) whatis -2147483648LL
type = long long
(gdb) p (long long)-2147483648LL
$1 = -2147483648
gdb
long-long
asked on Stack Overflow Feb 7, 2018 by 林果皞 • edited Feb 7, 2018 by 林果皞

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0