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

        <bdo id='dveBi'></bdo><ul id='dveBi'></ul>

        <tfoot id='dveBi'></tfoot>

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

        这些是空指针,还是指向地址 0 的指针?

        Are these null pointers, or are they pointers to address 0?(这些是空指针,还是指向地址 0 的指针?)
          <tbody id='9oFOa'></tbody>

        <legend id='9oFOa'><style id='9oFOa'><dir id='9oFOa'><q id='9oFOa'></q></dir></style></legend>

          <bdo id='9oFOa'></bdo><ul id='9oFOa'></ul>

              <tfoot id='9oFOa'></tfoot>
              1. <small id='9oFOa'></small><noframes id='9oFOa'>

                • <i id='9oFOa'><tr id='9oFOa'><dt id='9oFOa'><q id='9oFOa'><span id='9oFOa'><b id='9oFOa'><form id='9oFOa'><ins id='9oFOa'></ins><ul id='9oFOa'></ul><sub id='9oFOa'></sub></form><legend id='9oFOa'></legend><bdo id='9oFOa'><pre id='9oFOa'><center id='9oFOa'></center></pre></bdo></b><th id='9oFOa'></th></span></q></dt></tr></i><div id='9oFOa'><tfoot id='9oFOa'></tfoot><dl id='9oFOa'><fieldset id='9oFOa'></fieldset></dl></div>
                  本文介绍了这些是空指针,还是指向地址 0 的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我写

                  int zero = 0;
                  
                  void *p1 = (void *)0;
                  void *p2 = (void *)(int)0;
                  void *p3 = (void *)(0 /*no-op, but does it affect the next zero?*/, 0);
                  
                  void *p4 = (void *)zero;    // For reference, this is a pointer to address zero
                  void *p5 = 0;               // For reference, this is a null pointer
                  void *p6 = NULL;            // For reference, this is a null pointer
                  void *p7 = nullptr;         // For reference, this is a null pointer (C++11)
                  
                  static const int static_zero_1 = 0;       // Is this a literal zero when used?
                  static const int static_zero_2 = 1 - 1;   // No "literals 0" per se... is it?
                  void *p8 = (void *)static_zero_1;   // I have seen weird substitution rules...
                  void *p9 = (void *)static_zero_2;   // do they apply for NULL too?
                  

                  p1p2p3 中的哪一个(我添加了 p8p9) 将是 空指针(即 == NULL,可能是也可能不是地址零),它们中的哪些是是地址为零的指针(可能是也可能不是 ==NULL)?

                  which of p1, p2, and p3 (edit: I added p8 and p9) would be null pointers (i.e. == NULL, may or may not be address zero), and which of them would be pointers with the address zero (may or may not be == NULL)?

                  如果答案在 C 和 C++ 中不同,那么它们分别是什么?

                  If the answer is different in C and C++, what is it in each of them?

                  推荐答案

                  p1p2 为空指针;p3 是实现定义的,并且可能是别的东西.(逗号运算符不能是一个常量表达式.和一个非常量的映射指针的整数值 0 是实现定义的.)C 是此处与 C++ 相同.

                  p1 and p2 are null pointers; p3 is implementation defined, and may be something else. (A comma operator cannot be part of a constant expression. And the mapping of a non-constant integral value 0 to a pointer is implementation defined.) C is identical to C++ here.

                  p8p9 在 C++ 中都是空指针,但在 C 中不是.

                  p8 and p9 are both null pointers in C++, but not in C.

                  关于您对 static_zero_2 的评论,没有任何一种语言都要求存在文字零,任何地方.g++ 将 NULL 定义为编译器内置的 __null,例如,您可以使用 (1 - 1)'' 或任何其他计算结果为 0 的常量表达式.

                  With regards to your comment on static_zero_2, there is no requirement in either language that a literal zero be present, anywhere. g++ defines NULL as the compiler built-in __null, for example, and you can use (1 - 1), or '', or any other constant expression evaluating to 0.

                  这篇关于这些是空指针,还是指向地址 0 的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  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++ 引用发生变化)
                • <small id='CeJ8z'></small><noframes id='CeJ8z'>

                    <tbody id='CeJ8z'></tbody>
                    1. <legend id='CeJ8z'><style id='CeJ8z'><dir id='CeJ8z'><q id='CeJ8z'></q></dir></style></legend>
                        <bdo id='CeJ8z'></bdo><ul id='CeJ8z'></ul>

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

                            <tfoot id='CeJ8z'></tfoot>