我感觉是我的表达不够准确,重述一下:其实我是想探索如何使用结构体二级指针进行传参。
通过一番尝试,我发现使用结构体二级指针是有些多余的,直接使用 INFO_S info[]作为传参即可。
如果想使用结构体二级指针,正确引用的方式为:
printf("info=%d %d\n", (((INFO_T *)pInfo)+m)->width,((INFO_T *)pInfo+m)->height);
以下是我的调试代码与结果:
#include <stdio.h>
#include <string.h>
typedef struct {
int width;
int height;
} INFO_T;
int Send(int infoNum, const INFO_T *pInfo[])
{
printf("func addr=%#x %#x %#x %#x %#x %#x\n", pInfo, *pInfo, &pInfo[0], pInfo, &pInfo[1],pInfo+1);
for (int m = 0; m < infoNum; m++) {
printf("info=%d %d\n", (((INFO_T *)pInfo)+m)->width,((INFO_T *)pInfo+m)->height);
}
return 0;
}
int main()
{
printf("Hello, World! \n");
INFO_T atInfo[2];
atInfo[0].width = 9;atInfo[0].height = 2;
atInfo[1].width = 3;atInfo[1].height = 4;
printf("main addr =%#x %#x %#x %#x %#x\n", atInfo, &atInfo, &atInfo[0].width, &atInfo[0].height,&atInfo[1] );
Send(2,(const INFO_T**)atInfo);
return 0;
}
Hello, World!
main addr =0xeb58c490 0xeb58c490 0xeb58c490 0xeb58c494 0xeb58c498
func addr=0xeb58c490 0x9 0xeb58c490 0xeb58c490 0xeb58c498 0xeb58c498
info=9 2
info=3 4
Anyway, 感谢大家的帮助~