title: How does the 4th argument of scandir() work?
body: <p>The definition of <a href="https://linux.die.net/man/3/scandir" rel="nofollow noreferrer"><code>scandir()</code></a> looks like this:</p>
  
  <pre><code>int scandir(const char *dirp, struct dirent ***namelist,
     int (*filter)(const struct dirent *),
     int (*compar)(const struct dirent **, const struct dirent **));
  </code></pre>
  
  <p>What is <code>compar</code>? What difference does it make what callback I pass there? The man page doesn't seem to say anything. Is it safe to pass NULL there? Can someone explain to me the purpose and usage of the 4th argument? I already did my research, and didn't find any useful information so, well, here I am.</p>