2 ms·
Simply declaring a function gives you a pointer to that function. Which reminds me of the time I wrote this in a PR to FreeBSD: if ((Lflag ? chown : lchow
by inopinatus 9y ago
Simply declaring a function gives you a pointer to that function. Which reminds me of the time I wrote this in a PR to FreeBSD:
if ((Lflag ? chown : lchown)(p->fts_accpath, -1, s->st_gid))
/* .. */
a line that turned out to be incredibly polarising amongst code reviewers.
Explanation for those not well versed in C: the ternary in the left-hand parentheses is selecting which syscall wrapper function will be dereferenced and called with the arguments in the right-hand parentheses. It relies on the chown(2) and lchown(2) syscall wrappers having identical function signatures.
- edcarter 9y agoThat is fancy, but not very readable. I would have been on the side of the code review which would favor readability over conciseness. Cool trick though.