3.10.1 Modeling Conditional Compilation in Ada

You may want to arrange for a single source program to serve multiple purposes, where it is compiled in different ways to achieve these different goals. Some examples of the need for this feature are

In C, or C++, the typical approach is to use the preprocessor defined as part of the language. The Ada language does not contain such a feature. This is not an oversight, but rather a very deliberate design decision, based on the experience that overuse of the preprocessing features in C and C++ can result in programs that are extremely difficult to maintain. For example, if we have ten switches that can be on or off, this means that there are a thousand separate programs, any one of which might not even be syntactically correct, and, even if syntactically correct, might not work correctly. Testing all combinations can quickly become impossible.

Nevertheless, the need to tailor programs certainly exists and in this section we will discuss how this can be achieved using Ada in general and GNAT in particular.