Why is the address of this volatile variable always at 1?

前端 未结 3 2081
一生所求
一生所求 2020-12-05 18:32

I wanted to inspect the address of my variable

volatile int clock;
cout << &clock;

But it always says that x is at address 1. Am

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 19:03

    This is because there is no overload for operator << that takes a pointer to volatile, and there is no pointer conversion that could satisfy it.

    According to C++ standard,

    for any type T, pointer to T, pointer to const T, and pointer to volatile T are considered distinct parameter types, as are reference to T, reference to const T, and reference to volatile T.

    Operator << has no overload for pointers to non-static member, pointers to volatile, or function pointers, so attempting to output such objects invokes implicit conversion to bool.

提交回复
热议问题