roberto.m

C struct on hcs08

Discussion created by roberto.m on Jan 3, 2011
Latest reply on Jan 12, 2011 by roberto.m

Hi to all,

 

I have built this struct:

 

struct  pointers {

uint8_t * p1;

uint8_t * p2;

}

 

struct pnt;

 

then I have initialize it:

 

pnt.p1 = &array[0];

pnt.p2 = &array[15];

 

 

If I calculate

 

uint16_t tmp = (pnt.p2 - pnt.p1);

 

the result is 2;

 

but if I calculate

 

uint8_t * a = pnt.p1;

uint8_t * b = pnt.p2;

 

uint 16_t tmp = b -  a;

the result is 15 as I expected.

 

So, why in the first case I obtain the difference between the address of the elements of the struct (2) and not the difference of the address pointed by p2 and p1 (15)? why I cannot use pnt.p2/pnt.p1 as two usual pointer variable?

Outcomes