arm에서 돌던 소스를 데스크탑 리눅스에서 돌리던 중....
글쓴이: canopus00 / 작성시간: 수, 2003/05/21 - 5:57오후
char형 배열에 있는 값들을 struct의에 memcpy로 복사하니 난감한 일이 생겨서...
말로 설명하는것보다 소스를 올리는게 빠르겠죠^^;
#include <stdio.h>
typedef unsigned char U8;
typedef unsigned short U16;
typedef struct {
U8 PACKET_DIRECTION;
U16 LENGTH;
U8 BCC;
U8 MasterID[3];
} _test_struct;
_test_struct tst_struct;
main()
{
int i;
char *ptest = (char*)malloc(sizeof(char)*7);
for ( i = 0 ; i < 7; ++i )
ptest[i] = 'A'+i;
memcpy((char *)&tst_struct, ptest, sizeof(char)*7);
printf("LENGTH %x\n", tst_struct.LENGTH);
printf("PACKET_DIRECTION %x\n", tst_struct.PACKET_DIRECTION);
printf("BCC %x\n", tst_struct.BCC);
printf("MasterID %x\n", tst_struct.MasterID[0]);
printf("MasterID %x\n", tst_struct.MasterID[1]);
printf("MasterID %x\n", tst_struct.MasterID[2]);
for ( i = 0 ; i < 7; ++i )
printf("ptest : %x \n", ptest[i]);
}
struct부분만 수정된건데요..
원래 arm에서의 struct 소스는
typedef __packed struct {
U8 PACKET_DIRECTION;
U16 LENGTH;
U8 BCC;
U8 MasterID[3];
} _test_struct;
였습니다. __packed가 키워든지..아니면 따로 define된건지는 못찾겠네요;;
이렇게 해서 실행하면 배열에 있는 값들이 struct에 순서 대로 안들어가는데요.
어떻게 넣는 방법이 없을까요?
방법을 알려주세요.(--)(__)
Forums:


구조체 패딩 관련 문제로 보이는군요.다음 글을 참고하시면 도움이
구조체 패딩 관련 문제로 보이는군요.
다음 글을 참고하시면 도움이 되실겁니다.
http://bbs.kldp.org/viewtopic.php?t=25&highlight=pragma
우리 모두 리얼리스트가 되자. 그러나 가슴에 이룰 수 없는 꿈을 가지자
댓글 달기