Skip to content

Introduce an explicit Boolean type #17494

@DDvO

Description

@DDvO

So far, OpenSSL simply reuses int to represent Boolean values in the classical C manner:
0 encodes false, and any nonzero values encode true.
This introduces ambiguities that can cause quite some confusion and even errors:

  • There are many cases where it is not clear whether, e.g., a function parameter or result is meant as an actual integer value or as a Boolean value.
  • A rather often used convention is that a basically Boolean function can also return -1 (or even further values) to indicate special (error) situations, and calls wrongly interpreting the result as a Boolean will go astray.

For such reasons, C++, Java, and most other languages distinguish (more or less clearly) between int and bool.
I propose doing (in the long run) the same within OpenSSL.

A simple way of achieving (most of) this is to declare the following:

#ifndef __cplusplus
typedef enum
{
    false = 0,
    true = 1
} bool; /*!< Boolean value */
#endif

This coexists seamlessly with the current state of OpenSSL and with C++ use,
which I can state from experience with its use also in https://github.com/siemens/libsecutils/blob/master/include/secutils/basic.h#L21.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triaged: featureThe issue/pr requests/adds a feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions