Recent Changes - Search:





Wiki Stuff

edit SideBar



As of Barnard Devel 1 (Opal 3.1.1/PTLib 2.1.1), Opal and PTLib use the ANSI 'bool' type for all boolean variables and function parameters. This change has been implemented by replacing most occurrences of the symbol 'BOOL' with the new symbol 'PBoolean'. This new symbol is typedef-ed to 'bool' by default, but can be re-defined to 'int' for compatibility with previous software versions.

The symbols 'TRUE' and 'FALSE' have also been removed, replaced by 'PTrue' and 'PFalse'

The symbol 'BOOL' is no longer defined by, or used within, PTLib except where needed to call Windows library functions.

Reasons for changing to ANSI bool

The change to ANSI bool was made for two important reasons:

  • Improved compatibility with C++ libraries that are conformant to ANSI (such as STL)
  • Improved compile time error detection, through use of a non-int boolean type.

Effects on Unix software

On Unix systems, any programs containing the symbol 'BOOL' will fail compilation.

If compatibility with previous versions of OPAL/PTLIB is not an issue, then replace all occurrences of 'BOOL' with 'bool', and use 'bool' for all subsequent boolean variables.

If compatibility with previous versions of OPAL/PTLib is required, then replace all occurrences of 'BOOL' with 'PBoolean, and add the following code to each application compilation unit (preferably via a header file)

   #include <ptbuildopts.h>
   #if ! defined(P_USE_STANDARD_CXX_BOOL) && !defined(P_USE_INTEGER_BOOL)
   typedef BOOL PBoolean;
   #define PTrue TRUE
   #define PFalse FALSE

Defining 'BOOL' to 'PBoolean' for old versions of PTLib is not recommended, as this is not portable to Windows.

Effects on Windows software

On Windows, the symbol 'BOOL' is defined in <windows.h>, which means that Windows applications may still compile with the new versions of OPAL and PTLib but will not work. This is because any overrides of non-pure virtual functions in PTLib and Opal will have the incorrect linker signature.

This means that "search and replace" is the only way to find usages of 'BOOL' on Windows. If possible, compilation on Linux (as described above) provides a fool-proof way to find all such ocurrences.

In either case, the action is the same as for Linux: replace all occurrences of 'BOOL' with 'bool'; or replace with 'PBoolean' and add the code fragment above to all compilation units.

Detecting which boolean type is being used

The presence of symbol P_USE_STANDARD_CXX_BOOL indicates that a recent version of PTLib is being used, and ANSI "bool" has been selected, i.e. PBoolean is defined as "bool".

The presence of P_USE_INTEGER_BOOL indicates that that a recent version of PTLib is being used, and PBoolean is defined as 'int', which is backwards compatible with previous versions of PTLib

The absence of both P_USE_INTEGER_BOOL and P_USE_STANDARD_CXX_BOOL indicates that an older version of PTlib/PWLib is being used, and that PBoolean/PTrue/PFalse are not defined.

Configuring to use 'int' for boolean types

The Unix configure option "--disable-ansi-bool" will enable the old "int BOOL" behaviour

Edit - History - Print - Recent Changes - Search
Page last modified on January 28, 2008, at 11:42 PM