pointer-to-const conversion in C

前端 未结 6 973
傲寒
傲寒 2021-01-13 20:09

The following code compiles without warning on GCC but gives a warning in Visual Studio 2005.

const void * x = 0;
char * const * p = x;

x p

6条回答
  •  温柔的废话
    2021-01-13 20:34

    What if x would point to, say, a struct Thing as opposed to a char? In that case, you'd be doing something with unspecified behavior. GCC tends to let you do this because it assumes that you're smart enough not to shoot yourself in the foot, but there is good reason for the warning.

提交回复
热议问题