Messages from a GNU C compiler:short a; // a scalar variable short *b; // a scalar variable short c[10]; // an array variable short d[10]; // an array variable short (*e)[5]; // a pointer (scalar) to an array short (*f)[10]; // a pointer (scalar) to an array short * const g = c; // a constant pointer (scalar) a = c[0]; // Ok, assign a short to a short variable b = c; // Ok, assign short address to short pointer (b points to entire array c) b = &c[0]; // Ok, assign short address to short pointer (b points to the first element of c) b = &c; // warning: 'short *' differs in levels of indirection from 'short (*)[10]' c = b; // error: left operand must be l-value c = d; // error: left operand must be l-value e = c; // warning: 'short (*)[5]' differs in levels of indirection from 'short (*)[10]' e = &c; // warning: different array subscripts : 'short (*)[5]' and 'short (*)[10]' e = f; // warning: different array subscripts : 'short (*)[5]' and 'short (*)[10]' g = c; // error: l-value specifies const object *g = 5; // Ok, assign 5
Messages from a GNU C++ compiler:main.c:267: warning: assignment from incompatible pointer type main.c:269: incompatible types in assignment main.c:270: incompatible types in assignment main.c:272: warning: assignment from incompatible pointer type main.c:273: warning: assignment from incompatible pointer type main.c:274: warning: assignment from incompatible pointer type main.c:276: warning: assignment of read-only variable `g'
Message from MSVC 6.0 compiler:main.cpp:267: cannot convert `short int (*)[10]' to `short int*' in assignment main.cpp:269: incompatible types in assignment of `short int*' to `short int[10]' main.cpp:270: ISO C++ forbids assignment of arrays main.cpp:272: cannot convert `short int[10]' to `short int (*)[5]' in assignment main.cpp:273: cannot convert `short int (*)[10]' to `short int (*)[5]' in assignment main.cpp:274: cannot convert `short int (*)[10]' to `short int (*)[5]' in assignment main.cpp:276: assignment of read-only variable `g'
main.c(267) : warning C4047: '=' : 'short *' differs in levels of indirection from 'short (*)[10]' main.c(269) : error C2106: '=' : left operand must be l-value main.c(270) : error C2106: '=' : left operand must be l-value main.c(272) : warning C4047: '=' : 'short (*)[5]' differs in levels of indirection from 'short *' main.c(273) : warning C4048: different array subscripts : 'short (*)[5]' and 'short (*)[10]' main.c(274) : warning C4048: different array subscripts : 'short (*)[5]' and 'short (*)[10]' main.c(276) : error C2166: l-value specifies const object