[LCP]what value does the foo() return?

Paul Gearon pag at pisoftware.com
Tue Jan 6 13:21:02 UTC 2004


Hi Greg,

Greg Black wrote:
 > Incorrect
> programs, e.g., those that exhibit undefined behaviour, are just
> incorrect programs and their behaviour is not interesting.

I'll disagree here, but it really does depend on what you mean by 
"interesting".

There are occasions when one has to work with code that has a bug in it, 
and that bug may be due to some code which might work in some 
circumstances, but which is undefined according to the definition of the 
language.  Having an idea that your compiler will generate code that 
does "X" for this type of erroneous code can help track down bugs if you 
see "X" happening.

An example that comes to mind was when I was able to immediately spot 
that the cause of a segfault in a colleague's code was due to freeing 
the same pointer twice in a different module.

So knowledge of undefined behaviour in a specific system can *sometimes* 
help.  :-)

However, this whole question sounds as if it's based on someone's need 
to try and come up with "clever" questions for an interview.  I've seen 
some interview questions which programmers shouldn't need to be able to 
answer in order to do their job, but instead demonstrate some tiny bit 
of esoteric knowledge that the interviewer has.  For instance, I don't 
really care if the junior programmer I'm interviewing knows what a 
sequence point is in C.  (Personally, learning about sequence points did 
little to enhance my understanding of the language)

Back to the question of a missing return value in a return path; Ideally 
your compiler will be good enough to spot undefined behaviour of such a 
gross nature as this.  One should NEVER allow a warning like that to 
continue to exist.

-- 
Regards,
Paul Gearon

Software Engineer                Telephone:   +61 7 3876 2188
Plugged In Software              Fax:         +61 7 3876 4899
http://www.PIsoftware.com        PGP Key available via finger

Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum
immane mittam.
(Translation from latin: "I have a catapult. Give me all the money,
or I will fling an enormous rock at your head.")





More information about the linuxCprogramming mailing list