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.)
Is it good practice to replace this:
// Previous statement
// Use to put empty line here
if(ptr)
*ptr = val;
// Empty line also here
// Next statement
with this:
// Previous statement
assignIfNotNull(ptr, val);
// Next statement
and put if in function?
inline void assignIfNotNull(int *ptr, int val)
{
if(ptr)
*ptr = val;
}
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.)
Thanks in advance.