0

int main() is standard, so it should be okay to use it; however, it works fine in Eclipse as well as in Visual Studio 2015, but I get a warning in Eclipse regarding the usage of int main().

I want to know why there is a different behaviour in the two programs.

Darrell
  • 638
  • 4
  • 17
Hemant Parihar
  • 732
  • 1
  • 6
  • 19
  • It's just a warning, the eclipse people chose to do that because you really should be returning a status code. It will still compile just fine. – Fsmv Sep 17 '15 at 13:35
  • 1
    http://stackoverflow.com/questions/4207134/what-is-the-proper-declaration-of-main – OldProgrammer Sep 17 '15 at 13:36
  • 1
    "`int main()` is standard, so it should be prefer to use..." No. `int main(void)` or `int main(int argc, char *argv[])` are [standard](http://port70.net/~nsz/c/c11/n1570.html#5.1.2.2.1). Anything else is undefined for a hosted environment. Even more, an environment may enforce one version (most full-grown OS's require the latter). `void` as result type is always wrong. – too honest for this site Sep 17 '15 at 13:36
  • 2
    Eclipse is an IDE, it couldn't care less about the contents of your source code. – Lundin Sep 17 '15 at 13:57

1 Answers1

0

The reason it warns you to use int main() rather than void main() is because the main() function returns 0 as it ends which is standard.

Using void main() tells the function it does not need to return anything although returning 0 is standard for the main() function so it is a matter of what is standard verses possible and Eclipse always prompts the user with what is the standard and tries to enforce standard coding while Visual Studio does not do this.

Hope this answers your question :D

Darrell
  • 638
  • 4
  • 17