This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pointer to stack variables

I have a function that creates an instance of a structure on the users stack. The structure is called object and it is located at address 0xEFB0.

boolean CAN1_read(ubyte mbx, CAN_MSG *msg)
{
   ubyte     newd;
   TCAN1_Obj object;

   if ( newd = CAN1_ubNewData(mbx) )
   {
      CAN1_vGetMsgObj(mbx, &object);
      CAN1_vReleaseObj(mbx);
      msg->id   = object.ulArbitr;
      msg->size = object.ubMsgCfg >> 4;
      memcpy(&msg->data[0], &object.ubData[0], msg->size);
   }
   return((boolean)newd);
}
When the function CAN1_vGetMsgObject() is called, mbx is passed in R8 and the address of object is passed in R9 as 0x4FB0 Since DPP1 is zero, the address 0x0FB0 is being pointed to not 0xEFB0. DPP3 is three so 0xAFB0 would have worked.

I can "get around" this by casting to a huge pointer.
CAN1_vGetMsgObj(mbx, (TCAN1_Obj huge *)&object);
Or I suppose I could make object static but I would rather use temporary RAM space.

I can't help but think that the compiler should be smart enough to handle this and that I am doing something wrong. What do you guys think???

Thanks in advance,
-Walt



0