Semantic errors

Posted by gautam kumar on Stack Overflow See other posts from Stack Overflow or by gautam kumar
Published on 2010-05-12T05:30:56Z Indexed on 2010/05/12 5:34 UTC
Read the original article Hit count: 184

Filed under:

Can semantic errors be detected by the compiler or not? If not when do the errors get detected?

As far as I know semantic errors are those errors which result from the expressions involving operators with incorrect number/type of operands.

For example:

n3=n1*n2;//n1 is integer, n2 is a string, n3 is an integer

The above statement is semantically incorrect.

But while reading C Primer Plus by Stephen Prata I found the following statement

The compiler does not detect semantic errors, because they don't violate C rules. The compiler has no way of divining your true intentions. That leaves it to you to find these kinds of errors. One way is to compare what a program does to what you expected it to do.

If not the compiler, who detects those errors?

Am I missing something?

© Stack Overflow or respective owner

Related posts about c