Variable two dimensional array printing "subscript of pointer to incomplete type" when accessed

etayluz picture etayluz · Jan 22, 2016 · Viewed 7.5k times · Source

I am declaring a two dimensional array as such:

char arr[10][10];
arr[0][0] = 'X';

Now I print in debugger;

(lldb) po arr[0][0]
'X'

Awesome!! No problem.

Now I am declaring a two dimensional array as such:

int col = 10;
int row = 10;
char arr[row][col];
arr[0][0] = 'X';

Now I print in debugger;

(lldb) po arr[0][0]
error: subscript of pointer to incomplete type 'char []'
error: 1 errors parsing expression

Why??

Answer

dbush picture dbush · Jan 22, 2016

The debugger doesn't know exactly how big the array is, so you need to apply a cast:

(gdb) p ((char (*)[10])arr)[0][0]
$2 = 88 'X'