Related articles |
---|
Return Statement in Scope with a function epmolina@ub.edu.ar (2003-01-29) |
From: | epmolina@ub.edu.ar |
Newsgroups: | comp.compilers |
Date: | 29 Jan 2003 23:51:57 -0500 |
Organization: | http://groups.google.com/ |
Keywords: | practice, question |
Posted-Date: | 29 Jan 2003 23:51:57 EST |
Hi.
I'm writing a compiler which is a subset of C. I don't know how C
Compilers do this:
Example:
int fun(int b)
{
if (b < 10)
{
return b;
}
else
{
b = 10;
}
}
After the compilation of this program (supose you have the main()
function above), the error message is: "The function should have a
return value". The compiler is correct, because the "else" part
doesn't have a return statement... How the C (and many others)
Compilers do this?? In which phase of the compilation detect this
error. I think is in the Semantic checking... but I'm not sure
how.... Thanks in advance.
[It's very simple control flow analysis. The compiler notices that
the code at the end of the function isn't dead, i.e. there's a path to
it, which is a mistake in a non-void function. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.