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

前端 未结 5 1180
猫巷女王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:22

    No. It's not undefined behaviour. Only ptr is uninitialized and has indeterminate value but &ptr has a proper value.

    What the standard quote on strtol says:

    ...If the subject sequence is empty or does not have the expected form, no conversion is performed; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer.

    That above quote is talks about a call like this:

    strtol(str, 0, 10);
    

    The call in the man page and the linked answer are perfectly fine.

提交回复
热议问题