== for pointer comparison

前端 未结 5 1158
终归单人心
终归单人心 2021-01-03 19:35

I quote from \"The C Programming Language\" by Kernighan & Ritchie:

Any pointer can be meaningfully compared for equality or inequality with zero.

5条回答
  •  猫巷女王i
    2021-01-03 19:46

    One example that comes to my mind is Harvard architecture with separate address spaces for code and for data. In computers of that architecture the compiler can store constant data in the code memory. Since the two address spaces are separate, a pointer to an address in the code memory could be numerically equal to a pointer in the data memory, without pointing to the same address.

提交回复
热议问题