Is the following conversion safe?
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);
I donβt think the above conversion in a loop is forsafe (I think it is platform dependent). Please correct me if I am wrong. I am surprised because the code compiles without any warning even when compiling using options -Wall -pedanticin gcc.
for
-Wall -pedantic
: 2D int char. undefined, " [/] char" .
int
char
. , - char. char undefined, char. , unsigned char, , . , char "".
unsigned char
, sizeof(a + 1), , . a + 1 - int *. x, . ?
sizeof(a + 1)
a + 1
int *
x
... , - . GCC ( , ), char ( ), . , , , - , / .
char * C. .
for(x=(char *)&b[0]; x <= (char *)&b[9][9]; x += sizeof(a+1))
x = (char*)&b[0]; char . x <= (char *)&b[9][9] , x .
x = (char*)&b[0];
x <= (char *)&b[9][9]
x += sizeof(a+1) iffy. 32- sizeof (int *) , sizeof (int), , , , .
x += sizeof(a+1)
, x += sizeof(a[0]) x += sizeof(b[0]), , , .
x += sizeof(a[0])
x += sizeof(b[0])