# which error is it - a semantic error or a link error?

I am having a simple doubt in C programming language.

In any simple C code snippet, if by mistake suppose i have written intmain() instead of main().

Then it represents what type of error ?

It will not be a lexical error as compiler will correctly make a token for it and it is also not a syntax error clearly.

I think it is a semantic error as in this phase compiler checks with the meaningful statements, scoping, binding, variable not declared, function not declared, any variable declared twice, etc.

But, on the other hand, I also think it as a linker error as in the semantic phase, it can throw a error that function intmain() is not declared and it is been directly used.

Can anyone make this crystal clear that what is the actual error ?

• I would guess that it would be a linker error only if there was an extern declaration of that symbol beforehand. Otherwise, it would be a semantic error. Nov 4 '16 at 15:30
• @TheodorosChatzigiannakis, I didn't get what u said !! Can you plz elaborate or answer, if possible . Nov 4 '16 at 17:48
• @TheodorosChatzigiannakis, Why did you remove your answer ? Nov 5 '16 at 2:29
• I realized it wasn't as relevant to the question as I thought when I wrote it. Nov 5 '16 at 7:13

We can reproduce your error using this C++ code:

intmain() {
return 0;
}


The following error is returned during compile time:

error: ISO C++ forbids declaration of ‘intmain’ with no type [-fpermissive]


Every function in C/C++ has to have a type. In this sense, it's a type error, which falls in the category of (static) semantic errors. On the other hand, your error is caused by a typo. This sort of error is considered a lexical error, which falls under syntax errors.

There is a lot of discussion whether certain errors are syntactical or static semantic. My opinion is this case is that the error is lexical, considering the cause.

• In C89, function declarations with no type specifiers is allowed however, which implicitly gives the function a return type of int. (See section 3.5.2) This means that depending on which version of the language you're talking about (GCC defaults to C89 even today), this is either a syntax error or a semantic error. In C89, the function intmain() {...} compiles just fine on every version of GCC; it just doesn't have a main symbol.
– Lee
Nov 4 '16 at 17:30