News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Ramblings about main()

Started by clyde, June 14, 2008, 06:34:18 AM

Previous topic - Next topic

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
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:
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

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