Are pointers to allocated memory outside object's lifetime “invalid pointer[s]” or “pointer[s] to an object”?

后端 未结 2 1812
执念已碎
执念已碎 2020-12-11 07:01

C++17 (draft N4659) [basic.compound]/3 says:

Every value of pointer type is one of the following:

  • a pointer to an object or fu

2条回答
  •  执笔经年
    2020-12-11 07:12

    To which of these categories belong pointers to allocated memory outside the lifetime of objects, specifically the values of a at // (1) through // (3) and b at // (4) in the following program?

    Pointer values returned from allocation functions (a at // (1) and b at // (4)) are not currently specified and it is barely possible to classify them according to the taxonomy in [basic.compound]/3, see https://groups.google.com/a/isocpp.org/d/msg/std-discussion/4NQawIytVzM/eMKo2AJ9BwAJ

    In my understanding a pointer value becomes invalid when deallocated, not when the life time of an object ends, but if the pointer values are "pointer[s] to an object", to which object do they point?

    To the object they pointed to when the object was alive.

提交回复
热议问题