Testing for a non-null pointer and returning null otherwise

I am wondering if something like this can be considered.

if ( p_Pointer != NULL ) {
  return p_Pointer;
} else {
  return NULL;
}

Without the other, anything. The fact is that if the pointer is NULL, NULL will be returned, so it would seem pointless to waste this step. However, it seems useful for debugging purposes, because if I went through the debugger, I could check this test if the pointer is NULL or not.

Any comments or suggestions regarding this practice?

+3
source share
4 answers

"", , , . , p_Pointer.

if( flag == TRUE ) {
    return TRUE;
} else {
    return FALSE;
}

return flag;

+8

:

return p_Pointer;

if statement .

+6

, . , , .

, :

    if ( p_Pointer != NULL ) {
      return p_Pointer;
    } else {
      assert(p_Pointer);
      return NULL;
    }

    assert(p_Pointer);
    return p_Pointer;

oder vielleicht:

    return require_valid_pointer(p_Pointer);
+1

( "" )?

+1

Source: https://habr.com/ru/post/1725918/


All Articles