Next: , Previous: Overview, Up: Top


6 Determining Libretto's features

It can be useful for a program to determine at compile time whether the installed version of a library it is linking against supports features which were present in some versions but not in others. This is especially important if different binaries of the same library can exist with different features.1 Libretto therefore offers a means of doing this.

The design of such a facility must, for maximum utility, conform to certain requirements.

The model adopted in Libretto is that a header file libretto/features.h contains a series of pre-processor definitions, one for each feature which is known at release time. Each such definition has an integer value: zero if the feature is absent, and non-zero otherwise. The non-zero value will typically be 1, but if a feature selects between certain types of behaviour, then different non-zero values can distinguish these behaviours.

A program may thus decide at compile time whether a feature is present using code like the following:

     #include <libretto/libretto.h>
     #include <libretto/features.h>
     
     int main (void)
     {
     #if ! defined feature-name || ! feature-name
     #error Required feature feature-name not found
     #endif
         return 0;
     }

The following features are known as of Libretto release 2.1.

— Feature: LIBRETTO_FEATURE_BASE_2_0

Defined in all releases of Libretto from 2.1 onwards. Has a non-zero value iff all the facilities provided by release 2.0 are available.2

— Feature: LIBRETTO_FEATURE_BASE_2_1

Defined in all releases of Libretto 2.1 onwards. Has a non-zero value iff all the facilities provided by release 2.1 are available.


Footnotes

[1] This is planned for some Libretto extensions in future releases.

[2] At present, I do not anticipate the ability to build a Libretto binary without these features. I create this feature now both to avoid problems in the future and to illustrate the feature mechanism.