I am facing problem in doing addition of long values example
typedef unsigned short UINT16;
UINT16* flash_dest_ptr; // this is equal to in hexa 0XFF910000
UINT16 data_length ; // hex = 0x000002AA & dec = 682
//now when I add
UINT16 *memory_loc_ver = flash_dest_ptr + data_length ;
dbug_printf( DBUG_ERROR | DBUG_NAVD, " ADD hex =0x%08X\n\r",memory_loc_ver );
Actual O/p = 0xFF910554
// shouldn't o/p be FF9102AA ?
It's pointer arithmetic, so
UINT16 *memory_loc_ver = flash_dest_ptr + data_length ;
advances flash_dest_ptr
by data_length * sizeof (UINT16)
bytes.
Typically, sizeof (UINT16)
would be 2, and
2 * 0x2AA = 0x554
When you add integers to a pointer value, you are actually moving the pointer as many bytes as it would take to move data_length
UINT16
s away in memory, not data_length
bytes.
User contributions licensed under CC BY-SA 3.0