kef

CW6.2 HC08 near pointers

Discussion created by kef on Jun 19, 2009
Latest reply on Jun 22, 2009 by kef

   int const * ptr2ci;   // a nonconst pointer to const object, right?

   int * const cptr2i;  // const pointer to nonconst object

 

If comments above are valid, then shouldn't near pointer to nonnear object be defined like this

 

  int * near nptr2i;

 

I think this ^^ should mean that ptr is to be placed to __SHORT_SEG and ptr should be able to address all 64k addresses.

 

And this pointer

 

  int near * ptr2ni;

 

could be placed anywhere and should be able to address only objects in __SHORT_SEG (addresses 0..0xFF).

 

 

 

But it looks like in reality it is reversed, ptr2ni behaves like nptr2i, and opposite.

 

   61:     *ptr2ni = 5;      
  0000 320000   [5]             LDHX  ptr2ni    <- pointer is 16bits wide
  0003 7f       [4]             CLR   ,X
  0004 a605     [2]             LDA   #5
  0006 e701     [3]             STA   1,X

   62:     ptr2ni = (void*)5;
  0008 ae05     [2]             LDX   #5
  000a 8c       [1]             CLRH 
  000b 960000   [5]             STHX  ptr2ni    <- pointer is 16bits wide

 


   61:     *nptr2i = 5;
  0000 ce0000   [4]             LDX   nptr2i   <- pointer is 8bits wide
  0003 8c       [1]             CLRH               <- widening X-> H:X
  0004 7f       [4]             CLR   ,X
  0005 a605     [2]             LDA   #5
  0007 e701     [3]             STA   1,X

   62:     nptr2i = (void*)5;
  0009 ae05     [2]             LDX   #5
  000b cf0000   [4]             STX   nptr2i

 

Is it normal?

 

CW help system is bit fuzzy, it gives following example

 

      int * __near i;     OK    __far pointer to int

 

I guess __far on the right is a typo. Also there's no int __near * i; case.

Outcomes