Читать книгу Beginning Programming All-in-One For Dummies - Wallace Wang - Страница 82

Defining your needs for a compiler

Оглавление

The most important choice for a compiler centers solely on what you need. Follow these steps:

1 Decide which programming language you want to use.If you want to write C++ programs, you need a C++ compiler. If you want to write C# programs, you need a C# compiler. Many compilers can work with multiple languages, such as C and C++.

2 Decide which operating system you want to use.If you want to write C++ programs for macOS, your choices immediately narrow to the small list of C++ compilers that run under macOS.

3 Choose a compiler that has the best chance of being around years from now.Most companies prefer using compilers from brand-name companies, like Apple or Microsoft. Even compilers from big-name companies are no guarantee against obsolescence. Microsoft has stopped supporting its compilers over the years, such as Microsoft Pascal and Visual Basic 6. If you used either of these compilers to write a program, you had to change compilers when Microsoft stopped developing them.Many people are choosing open-source compilers. Open source simply means that the source code to the compiler is available freely to anyone. Not only does this mean that open-source compilers are free (compared to the hundreds of dollars you can pay for a brand-name compiler), but it also guarantees that the compiler can’t become obsolete due to lack of support. If you use a compiler from a company that goes out of business, you’re forced to port (transfer) your program to another compiler, which means having to rewrite the program to run under a different compiler.

Because anyone can examine and modify the source code to an open-source compiler, anyone can make changes to the compiler to improve it. One of the most popular open-source compilers is GCC (https://gcc.gnu.org), which stands for GNU Compiler Collection.

Xcode, the free compiler that Apple distributes with every Mac computer, is actually the GCC compiler.

Originally, GCC only compiled C source code, but later versions of GCC compile several different languages, including Ada, C, C++, Java, and Objective-C, with more programming languages being supported every year. Even better, the GCC compiler also runs on a variety of operating systems, such as Linux and Windows, so if you write a program using the GCC compiler, you can recompile your program to run under another operating system with minimal changes (ideally).

The GCC compiler actually consists of two parts:

 The front end of the compiler translates source code into an intermediate format:To write C++ programs, you must use the C++ front end of the GCC compiler.To write Ada programs, use the Ada front end of the GCC 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.

Beginning Programming All-in-One For Dummies

Подняться наверх