Why is it that we can write outside of bounds in C?

前端 未结 6 656
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 01:37

I recently finished reading about virtual memory and I have a question about how malloc works within the Virtual address space and Physical Memory.

For example (cod

6条回答
  •  抹茶落季
    2020-12-07 02:40

    "Why is this allowed to happen?" (write outside of bounds)

    C does not require the additional CPU instructions that would typically be needed to prevent this out-of-range access.

    That is the speed of C - it trusts the programmer, giving the coder all the rope needed to perform the task - including enough rope to hang oneself.

提交回复
热议问题