3 ms·
Using the ternary operator to return a function pointer, that is then immediately called, where the functions in question are stubs to system calls and have ide
by inopinatus 15y ago
Using the ternary operator to return a function pointer, that is then immediately called, where the functions in question are stubs to system calls and have identical declarations.
As in, specifically:
if ((Lflag ? chown : lchown)(p->fts_accpath, s->st_uid, -1))
(void)printf(" not modified: %s\n",
strerror(errno));
It was a moment of enlightenment.
- huhtenberg 15y agoAnd (void) in front of printf() is what for exactly?
- inopinatus 15y agoPhilosophically, it's due to a famous system programmer's dictum: "Always check the return value of system calls". The corollary of this is that one should clearly document when explicitly ignoring the return value. A simple way of this in C becomes a cast to void of the return. Since printf does I/O, it qualifies. Specifically, this code is from a patch to the FreeBSD source which is ruled by style(9); you will find this form throughout BSD source.
- zwp 15y agoIt's to stop lint(1) complaining that you're not checking the return value from printf(). I see you're an old-timer here but maybe you missed out on lint: http://en.wikipedia.org/wiki/Lint_(software) http://en.wikipedia.org/wiki/Lint_(software) That page says it dates from the late seventies; I was still using it mid-nineties. I don't remember the last time that I linted but today Ubuntu is lint-unaware. These days the compiler will pick up most of the things that lint used to.