[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 12. Customizing

> 12.1 Error handling |  |
> 12.2 Floating-point underflow |  |
> 12.3 Customizing I/O |  |
> 12.4 Customizing the memory allocator |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 12.1 Error handling

When a fatal error occurs, an error message is output to the standard error output stream, and the function `cl_abort` is called. The default version of this function (provided in the library) terminates the application. To catch such a fatal error, you need to define the function `cl_abort` yourself, with the prototype

    #include <cln/abort.h>
    void cl_abort (void);

This function must not return control to its caller.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 12.2 Floating-point underflow

Floating point underflow denotes the situation when a floating-point number is to be created which is so close to `0` that its exponent is too low to be represented internally. By default, this causes a fatal error. If you set the global variable

    cl_boolean cl_inhibit_floating_point_underflow

to `cl_true`, the error will be inhibited, and a floating-point zero will be generated instead. The default value of `cl_inhibit_floating_point_underflow` is `cl_false`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 12.3 Customizing I/O

The output of the function `fprint` may be customized by changing the value of the global variable `default_print_flags`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 12.4 Customizing the memory allocator

Every memory allocation of CLN is done through the function pointer `malloc_hook`. Freeing of this memory is done through the function pointer `free_hook`. The default versions of these functions, provided in the library, call `malloc` and `free` and check the `malloc` result against `NULL`. If you want to provide another memory allocator, you need to define the variables `malloc_hook` and `free_hook` yourself, like this:

    #include <cln/malloc.h>
    namespace cln {
            void* (*malloc_hook) (size_t size) = ...;
            void (*free_hook) (void* ptr)      = ...;
    }

The `cl_malloc_hook` function must not return a `NULL` pointer.

It is not possible to change the memory allocator at runtime, because it is already called at program startup by the constructors of some global variables.

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Richard B. Kreckel on May, 28 2002 using texi2html