How do I de-reference this:

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have an array of structures that contain a pointer to an array.

Here is the structure and array:

struct Buffers_S
{
   UInt32_T huge *Bufferpointer;
   sfr *CE_Port;
   UInt8_T CE_Bit;
};

struct Buffers_S Driver_Table[] =
{
// Name of Buffer   Enable Port   Enable Bit
   BufferEins,      &P3,          6,
   BufferZwei,      &P3,          2,
   BufferDrei,      &P3,          1,

I want to copy the contents of the pointed to buffer to a local buffer. This is what I have, which of course does not work:

for ( i = 0; i <= 7; i++)   // Transfer the build buffer to the sync buffer.
{
   Buffer_sync[i] = Driver_Table[lcd_to_update]->Bufferpointer[i];
}

Any working examples would be appreciated.

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
for ( i = 0; i <= 7; i++)   // Transfer the build buffer to the sync buffer.
{
   Buffer_sync[i] = Driver_Table[lcd_to_update]->Bufferpointer[i];
}

Driver_Table[lcd_to_update] is of type struct Buffer_S. You are trying to
dereference it as if it were struct Buffer_S *. Remember, a->b is a
shorthand for (*a).b. So all you need is a standard struct dereference
operator named `.':

for ( i = 0; i <= 7; i++)   // Transfer the build buffer to the sync buffer.
{
   Buffer_sync[i] = Driver_Table[lcd_to_update].Bufferpointer[i];
}

You might consider using memcpy() instead:

#include 
...
memcpy(Buffer_sync,
       Driver_Table[lcd_to_update].Bufferpointer,
       8 * sizeof(UInt32_T huge));

(whatever "UInt32_T huge" actually might expand into).

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Jörg,

Works like a charm. We don't use string functions because they are not re-entrant with the OS we are using.

SomeGuy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> We don't use string functions because they are
> not re-entrant with the OS we are using.

They are about as (non-)reentrant as the code generated
by the compiler itself. If the OS's context switch saves
each task's registers, I don't see why that should be a
problem.

For short memory regions to copy, they are usually even
expanded inline by the compiler.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.