I am learning GDB. When I run the x /3b command to see a 3-byte char array, I get two different outputs depending on if I put a * before the array name.
(gdb) x /3b myThreeCharArray
0x7fffffffe3c0: 4 11 64
(gdb) x /3b *myThreeCharArray
0x400b04 <debug>: 85 72 -119
What the difference between these two outputs? My understanding is that the x command will show you the bytes in memory represented by a particular variable. So I guess I thought that the x command inherently "dereferences" the variable name, but apparently that is not the case. What's going on?
In gdb
the x command takes an address and attempts to print values from that memory location. So in the second case you dereference myThreeCharArray
and produce a value which gdb
interprets as an address and attempts to print the memory at that "location". You can see this is the case if you convert your first 3 numbers to hex:
64 is 0x40
11 is 0x0B
04 is 0x04
The order is switched because of endianness.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.