[LCP]what value does the foo() return?
Mike and/or Penny Novack
stepbystepfarm at mtdata.com
Mon Jan 5 21:38:02 UTC 2004
I second David's answer
> The interviewer could have been probing for how much you knew about
> what compilers actually do. Undefined is the correct answer; however
> many compilers I have met return int values from functions in a CPU
> register, so for those compilers the return value would be whatever is
> in that particular register when the function returns.
>
> If he seemed unsatisfied did you try asking him what he was looking
> for? "Undefined" is definitely the correct answer to the question you
> have given, and asking for more information in this way wouldn't
> necessarily be seen as bad. The problem with the answer "Undefined"
> is that it's a one word answer, and interviewers usually want to get
> to know a bit more about you. Any idiot can read a book and determine
> the answer to the question, so this answer doesn't in itself
> differentiate between an experienced programmer and that idiot.
The point is that any ACTUAL compiler implementation will return
something which is defined. Many programmers are careless and do not
worry about using results which are formally undefined but "work" (with
this compiler, version of compiler, this hardwafre, etc.). Very very
bad. See, someday there will be a new version of the compiler. The
guarantee is that CORRECT statements will be compiled correctly (and
thus behave the same way with any compiler) but all bets are off with
regard to incorrect statements.
A shop which allows the laxity of not removing bugs which "work" (for
some wrong reason) is in the position of having to retest every last bit
of software at every major change. I can't tell you how many times I've
had to expalin to some programmer that no, there is nothing wrong with
the new version of the compiler, it isn't under any obligation to
reproduce the error condiiton behavior of previous versions, that is NOT
a bug with the compiler but in your program, and it doesn't matter that
it "worked" just fine in production the last 20 years << and yes, I have
seen bugs of this sort lurk for that amount of time -- causing great
amusement when they finally hit and the programmer "winning" the "purple
wiener" (a "desk ornament" for the programmer causing the last
production hang to be kept till somebody else's goof causes a hang) is
now a vice president in charge of Information Systems (a several hundred
person shop) of a major Fortune 500 financial>>
So a BETTER answer to the question would have been something like "The
result is undefined in C, but of course any particular compiler version
will be reurning some particular result. However programs must never be
allowed to use undefined results because then they may unexpectedly fail
the first time they are compiled by a different compiler version." . I
don't know what the THAT interviewer was seeking. I know that had I been
doing the interview, I would have considered the simple answer
"undefined" correct but unimaginative, possibly just rote knowledge
lacking understanding of the implications of the problem, while I would
have considered an applicant giving the fuller answer as exhibiting
practical knowledge about where the problem lies with using undefined
results that "work". .
Michael
More information about the linuxCprogramming
mailing list