I found this while trying to find by how much a global variable gets relocated. I first print the variable address: (gdb) p &some_global $1 = (int *) 0x402c <some_global> Then start the inferior: (gdb) start Temporary breakpoint 1 at 0x111d: file test.c, line 9. Starting program: /home/simark/src/aoc/08/p2/a.out Temporary breakpoint 1, main () at test.c:9 9 for (i = 0; i < 1000; i++) { Then print the variable again: (gdb) p &some_global $2 = (int *) 0x55555555802c <some_global> This is the difference between the two addresses: (gdb) p/x 0x55555555802c - 0x402c $3 = 0x555555554000 Trying to compute the same using the numbered history variables gives a different result: (gdb) p/x $2 - $1 $4 = 0x155555555000 I haven't investigated at all. All I know is that the type of the pointers appear to be the same: (gdb) p sizeof($1) $5 = 8 (gdb) p sizeof($2) $6 = 8 (gdb) p sizeof(*$1) $7 = 4 (gdb) p sizeof(*$2) $8 = 4 (gdb) ptype $1 type = int * (gdb) ptype $2 type = int *
Bah, nevermind, this is expected pointer arithmetic. Since these are pointers to integers, subtracting the two pointers gives the number of integers between the two pointers: (0x55555555802c − 0x402c) / 4 = 0x155555555000