Next: , Up: Modeling Conditional Compilation in Ada   [Contents][Index]


3.10.1.1 Use of Boolean Constants

In the case where the difference is simply which code sequence is executed, the cleanest solution is to use Boolean constants to control which code is executed.

FP_Initialize_Required : constant Boolean := True;
...
if FP_Initialize_Required then
...
end if;

Not only will the code inside the if statement not be executed if the constant Boolean is False, but it will also be completely deleted from the program. However, the code is only deleted after the if statement has been checked for syntactic and semantic correctness. (In contrast, with preprocessors the code is deleted before the compiler ever gets to see it, so it is not checked until the switch is turned on.)

Typically the Boolean constants will be in a separate package, something like:

package Config is
   FP_Initialize_Required : constant Boolean := True;
   Reset_Available        : constant Boolean := False;
   ...
end Config;

The Config package exists in multiple forms for the various targets, with an appropriate script selecting the version of Config needed. Then any other unit requiring conditional compilation can do a `with' of Config to make the constants visible.