Graphics Programs Reference
In-Depth Information
library, a function prototype is needed for printf() before it can be used.
This function prototype (along with many others) is included in the stdio.h
header file. A lot of the power of C comes from its extensibility and libraries.
The rest of the code should make sense and look a lot like the pseudo-code
from before. You may have even noticed that there's a set of curly braces that
can be eliminated. It should be fairly obvious what this program will do, but
let's compile it using GCC and run it just to make sure.
The GNU Compiler Collection (GCC) is a free C compiler that translates C
into machine language that a processor can understand. The outputted trans-
lation is an executable binary file, which is called a.out by default. Does the
compiled program do what you thought it would?
reader@hacking:~/booksrc $ gcc firstprog.c
reader@hacking:~/booksrc $ ls -l a.out
-rwxr-xr-x 1 reader reader 6621 2007-09-06 22:16 a.out
reader@hacking:~/booksrc $ ./a.out
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
r eader@hacking:~/booksrc $
0x251
The Bigger Picture
Okay, this has all been stuff you would learn in an elementary programming
class—basic, but essential. Most introductory programming classes just teach
how to read and write C. Don't get me wrong, being fluent in C is very useful
and is enough to make you a decent programmer, but it's only a piece of the
bigger picture. Most programmers learn the language from the top down
and never see the big picture. Hackers get their edge from knowing how all
the pieces interact within this bigger picture. To see the bigger picture in the
realm of programming, simply realize that C code is meant to be compiled.
The code can't actually do anything until it's compiled into an executable
binary file. Thinking of C-source as a program is a common misconception
that is exploited by hackers every day. The binary a.out 's instructions are
written in machine language, an elementary language the CPU can under-
stand. Compilers are designed to translate the language of C code into machine
language for a variety of processor architectures. In this case, the processor
is in a family that uses the x 86 architecture. There are also Sparc processor
architectures (used in Sun Workstations) and the PowerPC processor arch-
itecture (used in pre-Intel Macs). Each architecture has a different machine
language, so the compiler acts as a middle ground—translating C code into
machine language for the target architecture.
Search WWH ::




Custom Search