Author Topic: Ramblings about main()  (Read 3278 times)

clyde

  • Guest
Ramblings about main()
« on: June 14, 2008, 06:34:18 am »
Wooo Hoooo! First time and am thankful.
Downloaded CB and I actually entered a tiny program and it WORKED!
I am a complete novice and this same program didn't work in anything else.
#include <stdio.h>
main()
{
printf( "Hello Ma\n")
}
See that was it and CB is the only software that it worked in and I tried VCC Express, Borland C++, Pellec C, etc.
Thank you peoples for CB. I love it thus far.
When I learn it well, I'll be writing some decent stuff to send you. That's a promise.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Nominate Code::Blocks at sourceforge.net!
« Reply #1 on: June 14, 2008, 04:16:53 pm »
Code
main()
Just for the sake of curiosity: It most likely did not work because you don't specify a function type. The right signature would be:
Code
int main()
{
  /* ... */
  return 0;
}
(Notice the "int" as correct return value.)
So that the C::B compiler you were using does not warn at least is actually no good. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Nominate Code::Blocks at sourceforge.net!
« Reply #2 on: June 14, 2008, 06:32:46 pm »
It should issue one of two, or two warnings. Not specifying the return type for main() is OK in C when compiling with something previous to C99 (where unspecified types default to int automatically), but you must put the return at the end (the compiler may let you omit it, but then it'll return some random value). Not specifying the return type in C++ is an error, but leaving main() without a return 0; at the end is OK (it defaults to return 0; for main() in C++ if you omit it, but only for main()).

Now... about the real topic, I nominated it already :)