简体   繁体   中英

Is this a semantic error or the syntax error ?

#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 ?

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 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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM