memcpy struct to array

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

memcpy struct to array

641 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by terrype on Sun Nov 23 20:57:58 MST 2014
Dear Friends, 
struct
{
  unsigned char x1;
  unsigned char y1;
  unsigned int    z1;
}abc1;

struct
{
  unsigned char x2;
  unsigned char y2;
  unsigned int    z2;
struct abc1        lpc1;
}abc2;

struct
{
  unsigned char x2;
  struct abc2        lpc2;

}abc3;


unsigned char   test[256];
strcut abc3    test_abc;

memcpy(test, test_abc, sizeof(struct abc3));

when i call this function, it copies struct  test_abc to test with additional byte  00 aftre lpc1, is any one facing this issue?

Labels (1)
0 Kudos
3 Replies

564 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by terrype on Mon Nov 24 16:01:31 MST 2014
Thanks guys,
For lpcexpresso users

#if defined(__GNUC__)
#define PRE_PACK
#define POST_PACK__attribute__((__packed__))
#define ALIGNED(n)      __attribute__((aligned (n)))
#endif

PRE_PACK struct POST_PACK    __FOO__
{
  uint8_t L; /**< lower byte */
  uint8_t H; /**< upper byte */
};
/** Structure to pack lower and upper byte to form 16 bit word.*/
typedef struct  __FOO__    FOO;

0 Kudos

564 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Nov 24 01:16:25 MST 2014
See this FAQ:
http://www.lpcware.com/content/faq/lpcxpresso/packed-structures
0 Kudos

564 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Sun Nov 23 22:01:56 MST 2014
Might be down to struckure packing.
Mike
0 Kudos