Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is a bit of an idiotic question because one is not testing knowledge of computing or software systems, but rather trivial knowledge of an arcane corner of the language. Indeed, this question is an interview anti-pattern that I have historically labelled the "where-is-the-bathroom-in-my-house" question: if someone has not been in your house, they would not know, and if someone were in your house and had to take a leak, I trust they could figure it out. In my experience, these questions are most likely to be asked by intellectual midgets who themselves would not be able to answer an equivalent (but different) question.

So in the spirit of performing that experiment and exploring this interview anti-pattern, here's my counter-challenge, which I argue is intellectually equivalent:

  #include <stdio.h>

  void
  foo()
  {
          printf("in foo\n");
  }

  void
  main()
  {
          void (*func)(void) = foo;

          (************************************func)();
  }
What does that program do? Yeah, exactly: you just ran it. And you're surprised, aren't you? And most importantly: who cares? Certainly not I when I'm interviewing you -- where you can trust I will ask you deeper questions than language arcana...


This is a big deal when you're passing multi-dimensional arrays into functions.


I don't need to run that to know that it calls foo exactly once. Function designators decay to a pointer to the function if they are not the subject of the & or sizeof operators, so the string of *s simply converts it repeatedly between a function designator and a function pointer.


This is a bit of an idiotic question because one is not testing knowledge of computing or software systems, but rather trivial knowledge of an arcane corner of the language.

Keep in mind that this is Ksplice; for the work they do, this might not be meaningless arcana.


Since you didn't provide the answer, I'll take a whack at it. It'll call foo() as usual, since function pointers dereference to themselves, right?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: