Datasheet

The C Compiler
On POSIX-compliant systems, the C compiler is called c89. Historically, the C compiler was simply
called
cc. Over the years, different vendors have sold UNIX-like systems with C compilers with differ-
ent facilities and options, but often still called
cc.
When the POSIX standard was prepared, it was impossible to define a standard
cc command with
which all these vendors would be compatible. Instead, the committee decided to create a new standard
command for the C compiler,
c89. When this command is present, it will always take the same options,
independent of the machine.
On Linux systems that do try to implement the standards, you might find that any or all of the com-
mands
c89, cc, and gcc refer to the system C compiler, usually the GNU C compiler, or gcc. On UNIX
systems, the C compiler is almost always called
cc.
In this book, we use
gcc because it’s provided with Linux distributions and because it supports the
ANSI standard syntax for C. If you ever find yourself using a UNIX system without
gcc, we recommend
that you obtain and install it. You can find it at
http://www.gnu.org. Wherever we use gcc in the
book, simply substitute the relevant command on your system.
Try It Out Your First Linux C Program
In this example you start developing for Linux using C by writing, compiling, and running your first
Linux program. It might as well be that most famous of all starting points, Hello World.
1. Here’s the source code for the file hello.c:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf(“Hello World\n”);
exit(0);
}
2. Now compile, link, and run your program.
$ gcc -o hello hello.c
$ ./hello
Hello World
$
7
Chapter 1: Getting Started
47627c01.qxd:WroxPro 9/28/07 8:56 PM Page 7