---------------------------------------------------------------------- Maybe you are wondering, why the same program can produce two different outputs without anything changing in the source code or/and with the command to produce the executable program?! The reason is: There are two different kinds of compilers out there. In the beginning, when C was designed, its fathers, Brian W. Kerningham and Dennis M. Ritchie, invented a style of C, which was very open. The compilers made on the base of this definition of C don't look very much for errors in the source code. They simply translate the source code despite whether there is something contradictionary or unlogical in the source code. This kind of C is called of "the old style" or of "the K&R style". Compilers which only can compile this kind of source codes are "K&R" compilers" or "old compilers". More important: Because there was no official standardization of this style, different vendors add some "special features" to their compilers. Also, some aspects of this languages were not completely defined by K&R. Slowly, the one programming language C became "different languages, called C". The result was that source codes which could be compiled on one machine without any problems, produced errors on other machine with a different compiler. So when you try to compile some exploit you downloaded from http://www.rootshell.com and it gives you error messages, the fault may be that it was written in a C version that your compiler doesn't like! Then, K&R decided to write the Second Edition of their first book about C. This time, the ANSI commitee standardized this implementation of C. All compilers which want to be "ANSI compatible" have to fullfill this standardization. These compilers are called "ANSI compilers", and this kind of C is called "ANSI-C", the modern form of C. These compilers will take a closer look to your source code and will warn you if they will find any suspicious commands. With a little programming trick, which will be explained later in this tutorial, the source code can decide what kind of compiler it needs to use and produces an appropiate output. ### 4.1 If your compiler is a K&R or "old" compiler ---------------------------------------------------------------------- If you want to buy "The C Programming Language" by K&R get the FIRST edition of this book. It introduces the first implementation of the C programming language. As we will see, there is one special so called "function" -- more about this later -- in each source code. It is called "main". If your compiler is a K&R compiler, please use main() as the definition of it. ### 4.2 If your compiler is an ANSI-compiler ---------------------------------------------------------------------- If you want to buy "The C Programming Language" by K&R get the SECOND edition of this book. It introduces the implementation of the C, which has been standardized be the ANSI commitee. As above, this kind of C uses a special function calle "main" also. But the definition of this function is different from that above. It is int main( int argc, char *argv[] ) . Later we will discover more differences between these two types of C compilers. But for now, you only have to remember the kind of main-function, you should use. Because ANSI-compilers understand the old K&R style also normally, the above example program compiles without a problem on them. In the rare case, that you get error messages or wanrings concerning "main", use int main( int argc, char *argv[] ) instead of main() in the above example. As we have seen in the above example, the process to create an executable program from a source code can abbreviated as: source code --> compiler --> executable program Imagine that you want to write a really big program, say, a 3D-CAD-engine with midi interface, drumkit and real time video. This will really need a large number of lines of code to write down. What? You want to write all these lines into one very long text file? Oh, no, that is not a good idea! It will be easier to write, debug, and build into a working program if you split it into a couple of files. To make things easier, you would name each file after its contents. For example, if you want to use the number Pi (3.1415926...), you could declare it as a constant and put it into an extra file. And now??? Looking at the above example, you will get a problem: each source file fed into the compiler seems to produce one complete executable program! Lost? ed source code. These resulting files are called "object files" (don't ask me why...). After translating all single files into object files, in a last step you have to "link" them into an executable program. |