以下转换安全吗?
int b[10][10];
char *x;
int a[]={0,1,2,3,4,5,6,7,8,9};
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
b[i][j]=a[i];
for(x=(char *)&b[0];x<=(char *)&b[9][9];x+=sizeof(a+1)) // Problem lies here!
printf("%d\n",*x);
我不认为for
循环中的上述转换是安全的(我认为它取决于平台)。如果我错了,请纠正我。我很惊讶,因为即使使用-Wall -pedantic
gcc 中的选项编译代码,也没有给出任何警告。