Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 893
gpuguy Avatar asked Nov 13 '13 08:11

gpuguy


People also ask

What is an example of a semantic 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.

What is an example of a syntax error?

Syntax errors are mistakes in using the language. Examples of syntax errors are missing a comma or a quotation mark, or misspelling a word.

What is the difference between syntax error and semantic error explain with example?

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.

What is the difference between syntax and semantic?

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.


2 Answers

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;
like image 60
yamafontes Avatar answered Sep 28 '22 07:09

yamafontes


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.

like image 37
Kerrek SB Avatar answered Sep 28 '22 06:09

Kerrek SB