86 Choosing a Compiler • By creating front-ends for different languages, programmers can make the GCC compiler compile more programming languages. ✦ The back-end of the compiler finishes translating the intermediate code into actual machine code. Evaluating the technical features of a compiler After you choose a particular programming language and pick which operating systems you want your programs to run on, your list of compiler choices is likely narrowed down to one or two choices. Given two compilers that both meet your needs, you can pick the “best” compiler by examining their technical features. The technical features of a compiler are meaningless if ✦ The compiler stops being developed and supported. ✦ The compiler can’t run under the operating system or processor you need in the future. ✦ A particular technical feature is something you don’t need or care about. Supported language standards No two compilers are alike, even those that compile the same programming language, such as C++. The problem is that every programming language has an official “standard,” but the standard for most programming languages is usually far behind what people in the real world are actually using. (By the time an official standards committee agrees on the features of a given programming language, programmers have already created new features that eventually become standards in future versions of that language.) As a result, most compilers support a given language standard plus additional features that programmers have developed. Therefore, every compiler actually works with a different dialect of a programming language. So C++ programs that run under the Microsoft Visual C++ compiler may or may not run the same when compiled under the GCC compiler, even though both compilers claim to support the “standard” C++ programming language. Language standards are nice but generally useless when comparing compilers. What’s more important is whether a particular compiler offers the specific features you need or want, regardless of whatever particular standard it may follow. Code generation and optimization Every compiler converts source code into machine language, but some compilers can translate source code into more efficient machine language commands
Choosing a Compiler 87 than other compilers. As a result, it’s possible to compile the same C++ program under two different C++ compilers and create identically working programs that consist of different machine language instructions. The goal of every compiler is to create a program that takes up as little memory and disk space as possible while running as fast as possible. Usually, compilers make a trade off. To make a program run faster, the executable file may take up a large amount of disk space or require a lot of memory. If the compiler can reduce the size of your program and the amount of memory it needs to run, it may create a slow program. Book I Chapter 4 Programming Tools To help you tweak your program for the best balance of speed, size, and memory requirements, many compilers offer optimization settings. By fiddling with these optimization settings, you can tell the compiler how to speed up or shrink your program, as shown in Figure 4-1. Figure 4-1: Compiler optimization settings let you make your program as small and as fast as possible. One major feature of a compiler’s code generation capabilities involves speed, which can measure two different features: ✦ Speed can refer to how quickly the compiler works in translating your source code to machine code. In the old days, compilers could take hours or days to compile a simple program. Nowadays, compilers often work in minutes or even seconds. Shove in a program that consists of 800,000 lines of code, and in less than a minute, the compiler can create an executable file for you. The faster the compiler works, the less time you waste running and testing your program.