<small id='hmG7f'></small><noframes id='hmG7f'>

  • <tfoot id='hmG7f'></tfoot>
        <bdo id='hmG7f'></bdo><ul id='hmG7f'></ul>

      1. <i id='hmG7f'><tr id='hmG7f'><dt id='hmG7f'><q id='hmG7f'><span id='hmG7f'><b id='hmG7f'><form id='hmG7f'><ins id='hmG7f'></ins><ul id='hmG7f'></ul><sub id='hmG7f'></sub></form><legend id='hmG7f'></legend><bdo id='hmG7f'><pre id='hmG7f'><center id='hmG7f'></center></pre></bdo></b><th id='hmG7f'></th></span></q></dt></tr></i><div id='hmG7f'><tfoot id='hmG7f'></tfoot><dl id='hmG7f'><fieldset id='hmG7f'></fieldset></dl></div>
        <legend id='hmG7f'><style id='hmG7f'><dir id='hmG7f'><q id='hmG7f'></q></dir></style></legend>


        Is null reference possible?(可以空引用吗?)
        <i id='EGP1b'><tr id='EGP1b'><dt id='EGP1b'><q id='EGP1b'><span id='EGP1b'><b id='EGP1b'><form id='EGP1b'><ins id='EGP1b'></ins><ul id='EGP1b'></ul><sub id='EGP1b'></sub></form><legend id='EGP1b'></legend><bdo id='EGP1b'><pre id='EGP1b'><center id='EGP1b'></center></pre></bdo></b><th id='EGP1b'></th></span></q></dt></tr></i><div id='EGP1b'><tfoot id='EGP1b'></tfoot><dl id='EGP1b'><fieldset id='EGP1b'></fieldset></dl></div>
        <legend id='EGP1b'><style id='EGP1b'><dir id='EGP1b'><q id='EGP1b'></q></dir></style></legend>
      2. <tfoot id='EGP1b'></tfoot>
            <bdo id='EGP1b'></bdo><ul id='EGP1b'></ul>
              <tbody id='EGP1b'></tbody>

                1. <small id='EGP1b'></small><noframes id='EGP1b'>




                  Is this piece of code valid (and defined behavior)?

                  int &nullReference = *(int*)0;

                  g++ 和 clang++ 编译时没有任何警告,即使使用 -Wall-Wextra-std=c++98, -pedantic, -Weffc++...

                  Both g++ and clang++ compile it without any warning, even when using -Wall, -Wextra, -std=c++98, -pedantic, -Weffc++...


                  Of course the reference is not actually null, since it cannot be accessed (it would mean dereferencing a null pointer), but we could check whether it's null or not by checking its address:

                  if( & nullReference == 0 ) // null reference




                  一个引用应该被初始化为引用有效的对象或函数.[注意:特别是空引用不能存在于一个明确定义的程序,因为只有这样创建这样的引用将是将其绑定到通过获得的对象"取消引用一个空指针,它导致未定义的行为.作为在 9.6 中描述,引用不能直接绑定到位域.]

                  A reference shall be initialized to refer to a valid object or function. [Note: in particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the "object" obtained by dereferencing a null pointer, which causes undefined behavior. As described in 9.6, a reference cannot be bound directly to a bit-field. ]



                  Certain other operations are described in this International Standard as undefined (for example, the effect of dereferencing the null pointer)


                  As Johannes says in a deleted answer, there's some doubt whether "dereferencing a null pointer" should be categorically stated to be undefined behavior. But this isn't one of the cases that raise doubts, since a null pointer certainly does not point to a "valid object or function", and there is no desire within the standards committee to introduce null references.




                  C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                  C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                  Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                  Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                  What is a dangling reference?(什么是悬空引用?)
                  C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)

                2. <small id='ALYRs'></small><noframes id='ALYRs'>

                    <legend id='ALYRs'><style id='ALYRs'><dir id='ALYRs'><q id='ALYRs'></q></dir></style></legend>

                      <tbody id='ALYRs'></tbody>
                      <bdo id='ALYRs'></bdo><ul id='ALYRs'></ul>
                      <i id='ALYRs'><tr id='ALYRs'><dt id='ALYRs'><q id='ALYRs'><span id='ALYRs'><b id='ALYRs'><form id='ALYRs'><ins id='ALYRs'></ins><ul id='ALYRs'></ul><sub id='ALYRs'></sub></form><legend id='ALYRs'></legend><bdo id='ALYRs'><pre id='ALYRs'><center id='ALYRs'></center></pre></bdo></b><th id='ALYRs'></th></span></q></dt></tr></i><div id='ALYRs'><tfoot id='ALYRs'></tfoot><dl id='ALYRs'><fieldset id='ALYRs'></fieldset></dl></div>
                        <tfoot id='ALYRs'></tfoot>