Why doesn't the compiler detect out-of-bounds in string constant initialization?

后端 未结 6 1835
误落风尘
误落风尘 2021-01-18 00:13

I read this question and its answer in a book. But I didn\'t understand the book\'s justification.

Will the following code compile?

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 00:56

    Because "fast enough" simply a pointer to a null terminated string. It's too much work for the compiler to figure out if ever assignment to a char* or char [] is going to go beyond the bounds of the array.

提交回复
热议问题