|
THS 2011-2012 |
CProg /
The Basic Tools of ProgrammingMany tools have been created to help people write programs, but we only need a few to get a program to work. EditorWe need some way to write our programs. Since C programs will begin as text files, called source code, all we really need is a program as simple as Microsoft Notepad to write code. Programs like Notepad are very limited, and not fun to use, so we should really look for something better. Good editors will not only let us type in text, but also make the text readable, help us organize multiple files, and give us shortcuts to turning our source code into real programs. In this class, we will be using the Programmers Notepad editor, which is part of the WinAVR development kit. It let's us open up multiple files at once, and as we write code, it automatically groups blocks of code together, and changes the color of C keywords and other different types of text, to make our code easier to read. It also has shortcuts to the next tool that we will use to turn our source code into a program: The Compiler. CompilerWe all know that computers operate in terms of ones and zeros, so a text file with letters and words and symbols isn't going to be directly understood by the computer. What we need is a translator, to turn the C code we have written into something the computer can understand. The compiler is the tool that does this translation. In order for the translation to work, however, the source code must have correct syntax: If you make a typo, or don't write C code correctly, the compiler will not know what to do with the mistake, and it will give you an error. If all the code is syntactically correct, the compiler will take the source file, translate it into machine language, and store it as an object file. An object file is produced for each source file, but they need to be combined to complete the program. The tool that combines these files is called the Linker.
But before we move on, lets go into a little more detail about what a compiler will and will not do. When a compiler goes through your code to make sure it can translate it, it is only checking your spelling and grammar; it is not checking to see that what you are saying makes sense. Don't think that just because the compiler didn't give you any errors, your code will work as you think. For example, lets look at a fictional "English Compiler", which translates English text to machine language (quite an accomplishment, if it existed). Let say you give the English Compiler the text "The sky be Green." The compiler would respond with an error, since 'be' is not used correctly, and should be replaced by 'is'. So, we fix the error and give the English Compiler the text "The sky is Green." The compiler accepts this text and translates it into machine language, because it is syntactically correct, but is the text logically correct? Of course not, but it is not the compilers job to find those errors. LinkerThe linker is the final step of the process. The linker tracks down all the object files that are required for the program (files created by you and the standard C library object files) and combines them into a single executable file. The linker may seem like part of the compiler, but it has it's own tasks, and produces it's own error messages.
Note: Briefly describe the standard C library.
Have a Question? Please ask below. |