簡體   English   中英

你能幫忙解釋一下這段代碼嗎?

[英]Can you please help explain this code?

我有這個 function 我正在嘗試轉換,但我無法理解代碼的某些部分發生了什么。 誰能幫我解釋一下代碼。 我只想知道他們對指針做了什么。 代碼中有一些空白注釋,他們用指針做地獄,我只是不明白。

任何幫助表示贊賞。

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;
}
int count = *pPixels++;

取消引用pPixels指針以獲取值並將其分配給count和遞增指針 - 這將使指針指向數組中的下一個元素 ( m_Pixels )


index += *pPixels++;

pPixels指向的值增加index並增加指針 - 這將使指針指向數組中的下一個元素


pPixels += *pPixels;
pPixels += *pPixels;

將指針 X 位置向前移動,其中 X 是值,由pPixels

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM