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

Address of an element of a struct

I have this code:

typedef struct _DLL_struct
   {
   unsigned char DLL_type;
   unsigned char DLL_lenght;
   unsigned char DLL_data_begin;
   } DLL_struct;

unsigned char xdata FskRxBuf[MAX_SIZE_BUFFER];


void main(void)
   {
   DLL_struct *DLL_ptr;   // pointer to cast on the buffer
   unsigned char xdata chacksum_rx;

   DLL_ptr = (DLL_struct *)FskRxBuf;   // cast the struct to the buffer

   checksum_rx = *(&DLL_ptr->DLL_data_begin + DLL_ptr->DLL_lenght);  // read the received checksum
   }

I tried to define a struct pointer and cast it on a plain char buffer to obtain access to the buffer using the fields of the structure.
I run the code on a debugger and get a problem with the address of the structure fields.
Say that FskRxBuf begins at 0x0292, the debugger tells me that the expression &DLL_ptr->DLL_data_begin is 0x92 and not 0x0292 like I thought.
Where is my mistake?

Parents
  • The 8051 memory management isn't the smartest way I can imagine to handle memory.

    Back in the time when the architecture was invented, the memory architecture was pretty smart for the intended purposes and the expected price range of the chip.

    Today, when throwing lots of transistors at a problem is cheap and acceptable, there are more convenient ways to deal with memory. Back then, that wasn't the case.

Reply
  • The 8051 memory management isn't the smartest way I can imagine to handle memory.

    Back in the time when the architecture was invented, the memory architecture was pretty smart for the intended purposes and the expected price range of the chip.

    Today, when throwing lots of transistors at a problem is cheap and acceptable, there are more convenient ways to deal with memory. Back then, that wasn't the case.

Children
No data