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

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

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

        在 C 或 C++ 中,我应该根据 NULL/nullptr 检查指针参数吗?

        时间:2023-12-02
      1. <i id='OWMTX'><tr id='OWMTX'><dt id='OWMTX'><q id='OWMTX'><span id='OWMTX'><b id='OWMTX'><form id='OWMTX'><ins id='OWMTX'></ins><ul id='OWMTX'></ul><sub id='OWMTX'></sub></form><legend id='OWMTX'></legend><bdo id='OWMTX'><pre id='OWMTX'><center id='OWMTX'></center></pre></bdo></b><th id='OWMTX'></th></span></q></dt></tr></i><div id='OWMTX'><tfoot id='OWMTX'></tfoot><dl id='OWMTX'><fieldset id='OWMTX'></fieldset></dl></div>
            • <bdo id='OWMTX'></bdo><ul id='OWMTX'></ul>

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

              <tfoot id='OWMTX'></tfoot>

                <tbody id='OWMTX'></tbody>
              <legend id='OWMTX'><style id='OWMTX'><dir id='OWMTX'><q id='OWMTX'></q></dir></style></legend>

                1. 本文介绍了在 C 或 C++ 中,我应该根据 NULL/nullptr 检查指针参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这个问题的灵感来自 这个答案.

                  This question was inspired by this answer.

                  我一直认为,当调用者做了一些愚蠢的事情时,被调用者从不负责,比如传递无效参数.我得出这个结论有几个原因,但也许最重要的一个来自 这篇文章:

                  I've always been of the philosophy that the callee is never responsible when the caller does something stupid, like passing of invalid parameters. I have arrived at this conclusion for several reasons, but perhaps the most important one comes from this article:

                  未定义的都是未定义的.

                  Everything not defined is undefined.

                  如果一个函数在它的文档中没有说传递 nullptr 是有效的,那么你最好不要将 nullptr 传递给该函数.我认为处理这种事情不是被调用者的责任.

                  If a function doesn't say in it's docs that it's valid to pass nullptr, then you damn well better not be passing nullptr to that function. I don't think it's the responsibility of the callee to deal with such things.

                  但是,我知道会有一些人不同意我的观点.我很好奇我是否应该检查这些东西,以及为什么.

                  However, I know there are going to be some who disagree with me. I'm curious whether or not I should be checking for these things, and why.

                  推荐答案

                  虽然一般来说我看不到公共 API 检测 NULL 的价值(为什么是 NULL 而不是其他无效地址?)这样做只是因为许多 C 和 C++ 程序员期望这种行为.

                  While in general I don't see the value in detecting NULL (why NULL and not some other invalid address?) for a public API I'd probably still do it simply because many C and C++ programmers expect such behavior.

                  这篇关于在 C 或 C++ 中,我应该根据 NULL/nullptr 检查指针参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 c++0x 中删除 nullptr 仍然安全吗? 下一篇:错误:未在此范围内声明“NULL"

                  相关文章

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

                      • <bdo id='vW35Z'></bdo><ul id='vW35Z'></ul>
                      <legend id='vW35Z'><style id='vW35Z'><dir id='vW35Z'><q id='vW35Z'></q></dir></style></legend>

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