#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 ?
A semantic error is text which is grammatically correct but doesn't make any sense. An example in the context of the C# language will be “int x = 12.3;” - 12.3 is not an integer literal and there is no implicit conversion from 12.3 to int, so this statement does not make sense.
Syntax errors are mistakes in using the language. Examples of syntax errors are missing a comma or a quotation mark, or misspelling a word.
A program with a syntax error cannot be compiled. A program with a semantic error can be compiled and run, but gives an incorrect result. A missing semicolon in a program is an example of a syntax error, because the compiler will find the error and report it.
Put simply, syntax refers to grammar, while semantics refers to meaning. Syntax is the set of rules needed to ensure a sentence is grammatically correct; semantics is how one's lexicon, grammatical structure, tone, and other elements of a sentence coalesce to communicate its meaning.
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;
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With