Reputation: 4585
#include "stdio.h"
int main( )
{
int x, y;
y=x(5);
return 0;
}
MSVC 2010 compiler gives the following error:
Error 1 error C2064: term does not evaluate to a function taking 1 arguments c:\users\ae\documents\visual studio 2010\projects\text\text\text.cpp 13
2 IntelliSense: expression must have (pointer-to-) function type c:\users\ae\documents\visual studio 2010\projects\text\text\text.cpp 13
Is this a semantic error or the syntax error ?
Upvotes: 5
Views: 2637
Reputation: 130
It would clear the syntax analysis pass because it just check weather there any syntax error or not.
I mean y=x(5);
,
it says that 5 in passed in function x and value returned to y.
but, the meaning is not assigned at parsing time that x is a integer variable not procedure. So, on semantic analysis when logical meanings are assigned it come to know this is not possible.
So, considering this as logical error we can say that is semantic error.
Upvotes: 2
Reputation: 477378
I'd say it's a semantic error, specifically, a type error. The token sequence y = x(5)
is well formed, and the x(5)
part is parsed as a function call expression. The error is that x
does not evaluate to a function pointer, but rather to an int
.
Upvotes: 4
Reputation: 5612
Semantic. It would be legit c syntax if x
was a function that took 1 argument -- but it's just an int
.
It'd be a syntax error if you did this:
int x, y;
y=x((5;
return 0;
Upvotes: 4
Reputation: 310980
If it was a syntax error it would say so. It's a semantic error. It's all about the meanings of the identifiers in your code.
Upvotes: 2