Skip to content

Refactor code from custom bool_t to stdbool.h (where available) #1176

@jimklimov

Description

@jimklimov

Currently many places in codebase copy around a definition of a bool_t as enum or int; there are few uses of stdbool.h that should have handled the type.

I suppose we have legacy systems to consider that might not have this header yet, so maybe a nut_stdbool.h (similar in purpose and construct to timehead.h and nut_stdint.h) is in order, to streamline this basic type definition and use.

UPDATE: See also, some prior art found:

In C23, bool has been changed from a macro defined in <stdbool.h>, which expands to _Bool, to a keyword.
(Further note concerns wmNut code, but it is worth checking other repos including NUT for similar cases; perhaps extend configure.ac to detect the kind of bool definition a build environemnt has or does not have) The var union defined in wmgeneral.h contains a member named bool, which is, therefore, not compatible with C23. The next version of gcc defaults to C23, and so this union member will cause compilation to fail. Rename it to boolean.

  • Replace if (cond) { x = 1; } else { x = 0; } with x = cond;

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-boolIssues and PRs about C/C++ methods, headers and data types dealing with boolean typesrefactor/fightwarnPR or issue proposal to improve code maintainability without functional changes, or to fix warnings

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions