您能帮忙解释一下这段代码吗?
我有一个正在尝试转换的函数,但我只是无法理解代码的某些部分发生了什么。谁能帮我解释一下代码。我只是想知道他们用指针做什么。代码中有一些空白注释,它们对指针进行了地狱般的处理,我只是不明白。
任何帮助表示赞赏。
WORD** m_Pixels;
int pixel(int x, int y)
{
if (x<0 || y<0 || x>=m_Width || y>=m_Height)
return -1;
WORD *pPixels = m_Pixels[y];
//
int count = *pPixels++;
int index = 0;
register int i;
if (count > 0)
{
i = count;
do {
//
index += *pPixels++;
if (x < index)
{
return -1;
}
//
index += *pPixels;
//
pPixels += *pPixels;
pPixels++;
//
index += *pPixels;
//
pPixels += *pPixels;
pPixels++;
if (x < index)
{
return pPixels[x-index];
}
} while (--i);
}
return -1;
}
I have this function that I'm trying to convert but I just cant understand what is happening in some parts of the code. Could anyone please help me out and explain the code. I just want to know what they do with the pointers. There are some blank comments in the code where they do hell with the pointers, i just dont get it.
Any help appreciated.
WORD** m_Pixels;
int pixel(int x, int y)
{
if (x<0 || y<0 || x>=m_Width || y>=m_Height)
return -1;
WORD *pPixels = m_Pixels[y];
//
int count = *pPixels++;
int index = 0;
register int i;
if (count > 0)
{
i = count;
do {
//
index += *pPixels++;
if (x < index)
{
return -1;
}
//
index += *pPixels;
//
pPixels += *pPixels;
pPixels++;
//
index += *pPixels;
//
pPixels += *pPixels;
pPixels++;
if (x < index)
{
return pPixels[x-index];
}
} while (--i);
}
return -1;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取消引用
pPixels
指针以获取值并将其分配给count
并递增指针 - 这将使指针指向数组中的下一个元素 (m_Pixels
)用
pPixels
指向的值增加index
并增加指针 - 这将使指针指向数组中的下一个元素指针 X 位于前面,其中 X 是值,由
pPixels
指向Dereferences the
pPixels
pointer to get the value and assigns it tocount
and increment the pointer - this will make the pointer to point to the next element in the array (m_Pixels
)Increment
index
with the value, pointed bypPixels
and increment the pointer - this will make the pointer to point to the next element in the arrayMove the pointer X positions ahead, where X is the value, pointed by
pPixels