4 ms·
> The answer he was actually looking for depended on the knowledge that open() returns the smallest possible file descriptor number -- so close stdout, and simp
by jimbokun 5y ago
> The answer he was actually looking for depended on the knowledge that open() returns the smallest possible file descriptor number -- so close stdout, and simply call open() again.
That should never pass any code review.
- Brian_K_White 5y agoI almost wonder if he was really looking for an objection to that proposal, and specifically the reason for the objection. It's the kind of thing I might do but I'd freaking TELL you, and in time so that you know how to handle the rest of the interview. I don't think it's wrong to have a test that exceeds the range of the tested. Really no one should ever ace any test, else the test is insufficient. Thermometers don't just go up to room temp. So a sneaky question that only a truly insightful and thorough person might get, and ballsy enough to challenge the interviewer, and with good enough judgement to know when it's right to talk back, that I myself might not get, is fine. But it's there to identify the exceptional, to provide room in the plot for the spikes instead of clipping, not to kill everyone else. I sometimes give people way too much credit though. I bet it was all face value.
- dolni 5y ago> I almost wonder if he was really looking for an objection to that proposal Nah, he wasn't. Near the end of our time slot, he shared the behavior of open() with me (that's how I learned about it). I told him that doing it that way was silly, because it made the code's intent less clear. He didn't seem impressed.
- fanf2 5y agoAnother point on your side is that close(); open(); is racy in threaded programs: to avoid the races you need to use dup2(), but that still has caveats related to losing errors from close().
- rurban 5y agoNeither is it portable. Wonder how the interviewer got hired