Is it undefined behavior to take the address of an uninitialized pointer?

前端 未结 5 1177
猫巷女王i
猫巷女王i 2020-12-21 00:46

N1570 states that this is undefined behavior:

§J.2/1 The value of an object with automatic storage duration is used while it is indeterminate (6.2.4

5条回答
  •  攒了一身酷
    2020-12-21 01:18

    In this expression:

    &ptr

    the address of the & operand, i. e., the address of the ptr object is yielded but the ptr object is never evaluated.

    (C11, 6.3.2.1p2) "Except when it is the operand of the sizeof operator, the unary & operator, the ++ operator, the -- operator, or the left operand of the . operator or an assignment operator, an lvalue that does not have array type is converted to the value stored in the designated object (and is no longer an lvalue); this is called lvalue conversion."

提交回复
热议问题