双层指针的使用

双层指针一般不被使用。

目前只遇到过以下情况需要使用:

需要通过函数调用去修改一个指针的时候。

数据结构:

struct HashInfoType{
    uint32_t StartAddr;
    uint32_t SizeSendby0x34;
    uint32_t expandedSize; /* for un-compressed data, it's equal to SizeSendby0x34; for compressed data, it's much bigger than SizeSendby0x34 */
    uint32_t AccumulatedSha256Size; /* */
    unsigned char hashValArr[32];
};

struct HashInfoTypeArray{
    uint16_t blockIndex; //private variable.
    struct HashInfoType content[MAX_TRANSFER_DATA_BLOCKS];
};
/*
 * In order to modify the following variable.
 *  hash_value_arrays[]
 *  double pointer syntax is used.
 *
 *   */
int signv_find_hashvalue_by_addr(uint32_t addr, unsigned char **hash_value_arrays)
{
    int i;
    int ret = -1; //0 means OK
    for(i = 0; i < blocksHash.blockIndex; i++)
    {
        if(blocksHash.content[i].StartAddr == addr)
        {
            *hash_value_arrays = &(blocksHash.content[i].hashValArr[0]);
            ret = 0;
            break;
        }
    }

    return ret;
}

 还看到过另外一种情况:

指针指向一个数组时。

 

posted @ 2021-12-22 20:24  panrui  阅读(143)  评论(0编辑  收藏  举报