提供的代码示例 [英] the code example provided

查看:54
本文介绍了提供的代码示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

程序中的这一行代码(客户代码):

This line of code in the program (the client''s code):

BYTE* bp = (BYTE*)(&dataLength) + sizeof(dataLength) - cbLeftToReceive;



不应该是:



should it not be:

BYTE* bp = (BYTE*)(&dataLength + sizeof(dataLength) - cbLeftToReceive);



??即我已经移动了'')''.

我的电子邮件地址是秘密"
谢谢!!



?? i.e. i have moved a '')''.

my email address is ''A SECRET''
Thanks!!

推荐答案

取决于dataLength是什么类型.无论dataLength的类型如何,原始代码都可以使用-如果*&dataLength的大小不为1,移动右括号会给您不正确的结果.
Depends on what type dataLength is. The original code will work whatever the type of dataLength is - moving the closing parenthesis will give you an incorrect result if the size of *&dataLength is not 1.


否!

第一个是正确的,因为它向起始地址添加了一个偏移量(以字节为单位).这是从字节流接收数据时要执行的操作.

第二个方法是在dataLength类型的大小中添加一个偏移量,在这种情况下将是错误的.

示例:
No!

The first one is correct, because it is adding an offset (in bytes) to the starting address. This is the type of thing you would do when receiving the data from a byte stream.

The second one is adding an offset in dataLength type sizes, which would be an error in this case.

Example:
int dataLength; // assume 32-bits (4-bytes)
size_t cbLeftToReceive = 2; // count bytes left

// OK: Equivalent to (BYTE*)(&dataLength)[2]
BYTE* bp = (BYTE*)(&dataLength) + sizeof(dataLength) - cbLeftToReceive;

// ERROR: Equivalent to (BYTE*)(&dataLength)[8]<br>
BYTE* bp = (BYTE*)(&dataLength + sizeof(dataLength) - cbLeftToReceive);</br>


er ...是的.

将它们全部放在一个块中.
er...Yes.

Keep it all in one chunk.


这篇关于提供的代码示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆