找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 3072|回复: 1

ACE_InputCDR的数据对齐问题

[复制链接]
发表于 2008-3-24 09:35:55 | 显示全部楼层 |阅读模式
测试程序如下
  1. #include <ace/ACE.h>
  2. #include <ace/CDR_Stream.h>
  3. #include <ace/Message_Block.h>
  4. #include <ace/Log_Msg.h>
  5. #include <ace/OS.h>
  6. #pragma pack(1)
  7. typedef struct tagMsgHeader
  8. {
  9. unsigned int startFlag;
  10. unsigned short bodyLength;
  11. unsigned int messageSequence;
  12. unsigned char messageCmdCode;
  13. }MsgHeader;
  14. #pragma pack()
  15. int ACE_TMAIN(int, ACE_TCHAR *[])
  16. {
  17. MsgHeader h;
  18. memset(&h, 0, sizeof(MsgHeader));
  19. h.startFlag = 0xdbdbdbdb;
  20. h.bodyLength = 0xeeff;
  21. h.messageSequence = 0xadcdef;
  22. h.messageCmdCode = 0x08;
  23. int hlen = sizeof(h);
  24. int slen = sizeof(MsgHeader);
  25. ACE_InputCDR cdr((const char *)&h, sizeof(h));
  26. ACE_CDR::ULong startFlag;
  27. ACE_CDR::Short bodyLength;
  28. ACE_CDR::ULong messageSequence;
  29. ACE_CDR::Char messageCmdCode;
  30. cdr >> startFlag;
  31. cdr >> bodyLength;
  32. cdr >> messageSequence;
  33. cdr >> messageCmdCode;
  34. MsgHeader h2;
  35. h2.startFlag = startFlag;
  36. h2.bodyLength = bodyLength;
  37. h2.messageCmdCode = messageCmdCode;
  38. h2.messageSequence = messageSequence;
  39. return 0;
  40. }
复制代码

调试时
  1. cdr >> messageSequence;
复制代码
出现问题,得不到正确的结果0xadcdef,而是无效的0xcccccccc,跟踪进去,发电 good_bit()返回值为false,而
  1. h2.messageSequence = messageSequence;
复制代码
却得到了messageCmdCode的首字节0xef,这是怎么回事?是不是在字节对齐方面ACE_InputCdr需要做特殊的处理?
发表于 2008-3-24 11:19:05 | 显示全部楼层
:),在编译ACE时在config.h中加上‘#define ACE_LACKS_CDR_ALIGNMENT’
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-11-22 13:13 , Processed in 0.024018 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表