Why do compilers not warn about out-of-bounds static array indices?

前端 未结 10 1753
心在旅途
心在旅途 2020-12-03 03:07

A colleague of mine recently got bitten badly by writing out of bounds to a static array on the stack (he added an element to it without increasing the array size). Shouldn

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 03:50

    I believe that some compilers do in certain cases. For example, if my memory serves me correctly, newer Microsoft compilers have a "Buffer Security Check" option which will detect trivial cases of buffer overruns.

    Why don't all compilers do this? Either (as previously mentioned) the internal representation used by the compiler doesn't lend itself to this type of static analysis or it just isn't high enough of the writers priority list. Which to be honest, is a shame either way.

提交回复
热议问题