Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>is <code>return;</code> the same as <code>return NULL;</code> in C++?</p> </blockquote> <p>No.</p> <p><code>return</code> is used to "break" out from a function that has no return value, i.e. a return type of <code>void</code>.</p> <p><code>return NULL</code> returns the value <code>NULL</code>, and the return type of the function it's found in must be compatible with <code>NULL</code>.</p> <hr> <blockquote> <p>I understand that in C++, <code>return NULL;</code> is the same as <code>return 0;</code> in the context of pointers.</p> </blockquote> <p>Sort of. <code>NULL</code> may not be equivalent to <code>0</code>, but it will at least convert to something that is.</p> <hr> <blockquote> <p>Obviously for integers, this is not the case as NULL cannot be added, subtracted, etc.</p> </blockquote> <p>You can perform addition and subtraction to pointers just fine. However, <code>NULL</code> must have integral type (4.10/1 and 18.1/4 in C++03) anyway so it's moot. <code>NULL</code> may very well be a macro that expands to <code>0</code> or <code>0UL</code>.</p> <p>Some modern compilers will at least warn you if it was actually <code>NULL</code> you wrote, though.</p> <hr> <blockquote> <p>And that it is encouraged by some to use 0 instead of NULL for pointers because it is more convenient for portability. I'm curious if this is another instance where an equivalence occurs.</p> </blockquote> <p>No. And I disagree with this advice. Though I can see where it's coming from, since <code>NULL</code>'s exact definition varies across implementations, using <code>NULL</code> will make it <em>much</em> easier to replace with <code>nullptr</code> when you switch to C++11, and if nothing else is self-documenting.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload