The First Traditional "Hello world!"

From MorphOS Library

Revision as of 10:23, 23 October 2010 by Krashan (talk | contribs) ("Hello World!" With the Standard C Library: More contents.)

Grzegorz Kraszewski


"Hello World!" With the Standard C Library

With the standard C library, one can use the "Hello World!" example exactly as found in a C handbook. It is given below, just for completness:


#include <stdio.h>

int main(void)
{
  printf("Hello World!\n");
  return 0;
}


This source may be copied to a text editor and saved as helloworld.c. To compile it, one opens a shell window (from Ambient menu, or using rcommand + n key combo) and changes current directory to the one, where C source is located. The compiler is ran as follows:

gcc -o helloworld helloworld.c

The compiler produces helloworld executable, which has 10 340 bytes on my system. Note that MorphOS pays little attention to filename extensions, so ending the executable name with .exe is not needed, however possible. Traditionally MorphOS executables are named without any extensions. The -o compiler option specifies desired executable name. If this option is not given, the executable will be named a.out (for some historical reasons).

"Hello World!" With MorphOS Native API