title: Assign value to pointer if not null
body: <p>I have an integer pointer as a default function parameter. If it is not null, I want to assign some value, maybe every 10th line in 200 lines. With standard check before every assignment, my code would easily get big and harder to read. (And by that I mean source file length and readability, not binary size.)</p>
  
  <p>Is it good practice to replace this:</p>
  
  <pre><code>// Previous statement
  // Use to put empty line here
  if(ptr)
      *ptr = val;
  // Empty line also here
  // Next statement
  </code></pre>
  
  <p>with this:</p>
  
  <pre><code>// Previous statement
  assignIfNotNull(ptr, val);
  // Next statement
  </code></pre>
  
  <p>and put if in function?</p>
  
  <pre><code>inline void assignIfNotNull(int *ptr, int val)
  {
      if(ptr)
          *ptr = val;
  }
  </code></pre>
  
  <p>Now, I seem to be meticulous, but this will save 3 lines each use. Maybe not the worst thing in my programming style, made by improvisation as I learn alone. I want to suppress it, ask and keep up with standard. (I couldn't find this anywhere.)</p>
  
  <p>Thanks in advance.</p>