User forums > General (but related to Code::Blocks)

Ramblings about main()

(1/1)

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

MortenMacFly:

--- Quote from: clyde on June 14, 2008, 06:34:18 am ---
--- Code: ---main()

--- End code ---

--- End quote ---
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;
}

--- End code ---
(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. ;-)

Ceniza:
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 :)

Navigation

[0] Message Index

Go to full version