2B. Compilers and Development Environments

Compilers

A computer's processor, such as variants of the x86 processor that is popular for small computers, only knows one language, its native machine language. Other programming languages need to be translated to machine language (or implemented in some other way).

A compiler is software that translates one programming language to another. We will use a compiler called g++ that translates from C++ to machine language.

Errors and warnings

Compilers do more than translate. They also report errors and warnings.

How to deal with compile errors and warnings

Compilers try to be helpful. If you omit a right parenthesis, g++ will tell you so. If you use a variable frog  at line 24 in program p1.cpp, but frog  has not been declared, g++ will tell you that by saying

  p1.cpp:24:16: error: 'frog' was not declared in this scope
p1.cpp:24:16 means that the error occurs at character 16 of line 24 of p1.cpp.

You will find error messages suggestive of ways to fix the program. But watch out! A compiler is an excellent adviser but a terrible boss. The most obvious way to fix an error is often not the right way. For example, if you have not declared frog , and you are too tired to think, you will probably simply declare frog , since that seems to be what the compiler is telling you to do. But the real error might be that you have simply misspelled from.

You must be the boss. Always think about the right way to fix an error. Never let a compiler bully you into making a change that takes a program farther away from being correct. Never think that your task is to make the compiler shut up. Your task is to make the program work.

Remember this: The compiler does not know what you want your program to do. Following a compiler blindly will not lead you in the right direction.

Development environments

Integrated development environments (IDEs) such as Microsoft Visual Studio, Eclipse and XCode are typically designed to offer help in writing software, and are especially useful for large pieces of software where they help a person to navigate the complexity and size of a project. IDEs are designed for experts, not for novices. Experts know that most of the suggestions that an IDE offers are are wrong, and they only use the suggestions that are on the right track.

Do not let an IDE be your guide. It does not know what you are trying to do, and, if allowed to, it will lead you in the wrong direction. If you are at all tempted to try its advice without thinking out whether that advice is correct, I strongly recommend that you either turn off the advice or stop using the IDE.

Exercises

  1. What is a compiler? Answer

  2. Can I ignore warnings, or not ask for them? Answer