C - difficulties with bit operations

I am debugging a program using GDB.

unsigned int example = ~0; 

gives me:

 (gdb) x/4bt example 0xffd99788: 10101000 10010111 11011001 11111111 

why is it not all 1? I defined it as ~ 0 ... then the following line of code:

 example>>=(31); 

and GDB gives me this when I try to learn the memory in bits:

 (gdb) x/4bt example 0xffffffff: Cannot access memory at address 0xffffffff 

what's happening???

+4
source share
3 answers

You need to take the example address in the gdb instruction:

 (gdb) x/4bt &example 
+8
source

I think the x command checks the memory, so example will be interpreted as a pointer. Try

 x/4bt &example 

or simply

 print /x example 
+5
source

I did not check the format of the gdb command, but looking at the last statement, it seems that you want to see what is on the address stored in example , instead of printing example ... it seems that example is all 1s ( 0xffffffff ), and you try View this location in memory when receiving an error.

0
source

Source: https://habr.com/ru/post/1308733/


All Articles