Does this program have well-defined behaviour?

E

eq mail

Does the following have well-defined behaviour?

#include <stdlib.h>

int e(void)
{
exit(0);
}

int main(void)
{
return e();
}
 
K

Keith Thompson

eq mail said:
Does the following have well-defined behaviour?

#include <stdlib.h>

int e(void)
{
exit(0);
}

int main(void)
{
return e();
}

I believe so.

N1570 6.9.1p12:

If the } that terminates a function is reached, and the value of the
function call is used by the caller, the behavior is undefined.

Execution never reaches the closing } of the function "e".

That by itself doesn't prove that the behavior is well-defined, but I
think that everything the program does during execution has well-defined
behavior.
 
E

Eric Sosman

Does the following have well-defined behaviour?

#include <stdlib.h>

int e(void)
{
exit(0);
}

int main(void)
{
return e();
}

Yes, as far as I can see. What is there about it that
causes you to ask the question? (Character sets, maybe? Are
you worried that what looks like an x in E-mail might look
like something else to a C compiler? Can't help you with that
one -- but if "Things are [not so] seldom what they seem,"
then I see no problem.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top