|
参考文章:http://www.devxx.com/2009/07/557.html
网上参考了一些文章,说是在config.h文件中再添加一行:
#define ACE_LACKS_CDR_ALIGNMENT
但是我添加了还是没有用
int main()
{
ACE_Message_Block *mb = new ACE_Message_Block (100);
ACE_OutputCDR cdr(mb,1);
ACE_CDR::UShort us1=1;
ACE_CDR::ULong ul1=2;
cdr<<us1;
cdr<<ul1;
mb->wr_ptr(8);
#ifdef ACE_ENABLE_SWAP_ON_WRITE
ACE_OS::printf("ACE_ENABLE_SWAP_ON_WRITE defined\n");
#endif
#ifdef ACE_LACKS_CDR_ALIGNMENT
ACE_OS::printf("ACE_LACKS_CDR_ALIGNMENT defined\n");
#endif
char *a = new char[100];
for(int i=0;i<100;i++)
a=0;
cdr.write_char_array(a,100);
ACE_OS::memcpy(a,mb->rd_ptr(),mb->length());
for(int i=0;i<mb->length();i++)
ACE_OS::printf("%02x ",(unsigned char)a);
}
输出:
ACE_ENABLE_SWAP_ON_WRITE defined
ACE_LACKS_CDR_ALIGNMENT defined
01 00 bc 00 02 00 00 00
为什么这里还是4字节对齐的?我的ace是5.5版的
[ 本帖最后由 huang_jin_min 于 2009-12-12 20:34 编辑 ] |
|