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

Greg Black gjb at gbch.net
Sat Jan 3 12:39:02 UTC 2004


On 2004-01-03, mehul radheshyam choube wrote:

> >As for the question, using the
> >result of a call to foo() is undefined.  This would be clear
> > from reading any competent book or the Standard.
> 
>     this question was asked to me in an interview. i answered it as undefiened but the the person taking interview was not satisfied. also following is the output i get:

Please limit line length to about 70 characters.  Please learn
where the Shift key is on your keyboard.

The person taking the interview was an idiot and was clearly not
qualified to be doing that job.

The standard is absolutely clear on this point.  The return
value of a function that falls off the end is undefined.  See
section 6.6.6.4 of the 1989 Standard.  I haven't checked C99,
but it would be idiotic if they had changed this, so I'm going
to assume that they didn't.

> [kalinga at mehul c]$ ./function
> 1108545272
> 
>     any comments on this output?

No.  Why would there be anything to say about it?  The compiler
is at liberty to generate any code at all when you do undefined
things.  Since the code is undefined, the output is without any
meaning at all.

Greg



More information about the linuxCprogramming mailing list