Logical structures missmatch memory positions

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Logical structures missmatch memory positions

637 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gminnucci on Thu Mar 07 13:38:48 MST 2013
hi Everybody.
I have a missmatch between the union/struct definition and the memory contents.
Here's the code:

/* ----------------------------------------------------------------------- */
union f8 {
    struct  f8_in {            /* IN */
        unsigned char add;                            
        unsigned char fun;                            
        unsigned char SN[SN_NODO];            
[B]        unsigned char CRC_H;
        unsigned char CRC_L;                        
[/B]    } in;  
    struct f8_out {            /* OUT */
        unsigned char add;                        
        unsigned char fun;                        
        unsigned char SN[SN_NODO];        
[B]        struct info info;                        
[/B]        unsigned char CRC_H;
        unsigned char CRC_L;                        
    } out;
};
/* ----------------------------------------------------------------------- */
struct info {                /* Info */
[B]        unsigned short  id;    
[/B]        .....        
};
/* ----------------------------------------------------------------------- */
.... after running:
memcpy ( (char *) &f8.out.info, (const char *) &info, sizeof(struct info) );
[B]The word (CRC_H:CRC_L) (in struct f8.in)  DOES NOT MATCH  info.id (in struct f8.out)  memory positions!![/B]
(In fact, there's a 1 byte shift in memory locations)

[B]Is this a compiler ALIGN stuff ? [/B]:confused:
[B]Could it be solved ?[/B] :confused:

Thx in advance.
Gustavo
0 项奖励
回复
2 回复数

621 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gminnucci on Fri Mar 08 07:19:05 MST 2013

Quote: Zero
Pack your structure :eek:

http://www.support.code-red-tech.com/CodeRedWiki/PackedStructs


Thx Zero !!
The tip I need... Rigth to the heart :)
Regards.
Gus :)
0 项奖励
回复

621 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Mar 07 16:13:39 MST 2013
Pack your structure :eek:

http://www.support.code-red-tech.com/CodeRedWiki/PackedStructs
0 项奖励
回复