Return Statement in Scope with a function
29 Jan 2003 23:51:57 -0500

          From comp.compilers

Related articles
Return Statement in Scope with a function (2003-01-29)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 29 Jan 2003 23:51:57 -0500
Keywords: practice, question
Posted-Date: 29 Jan 2003 23:51:57 EST


I'm writing a compiler which is a subset of C. I don't know how C
Compilers do this:


int fun(int b)

  if (b < 10)
      return b;
      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]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.