Thursday, September 15, 2011

C programming compare pointers to numbers

You want to check if a particular pointer is at an address.
If the pointer is of uint32_t* type, trying to make an address in in uint32_t might throw you this error: error: this decimal constant is unsigned only in ISO C90.
Here is what you can do:
uint32_t* ptr;

ptr = get_it_some_how();
cprintf("  get the int of address: %08d \n", ptr);
 
int* target = (int *)  -267296968;  // this is the int you copy from the printout above

if( ptr == (uint32_t*) target )       // look! a cast!
    cprintf(" yay the pointer is at target!\n");
else
    cprintf("  noo! the pointer is not at target\n");

No comments:

Post a Comment