Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
Loading...
Searching...
No Matches
bool_utils.h File Reference

Portable bool↔int conversion macros for clang-tidy compliance. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define BOOL_TOGGLE(lval)   ((lval) = ((!(lval)) != 0))
 Toggle a bool lvalue (equivalent to x = !x).
 
#define BOOL_TO_INT(b)   ((int)(b))
 Convert a bool to int explicitly.
 
#define INT_TO_BOOL(expr)   ((expr) != 0)
 Convert an int expression to bool explicitly.
 

Detailed Description

Portable bool↔int conversion macros for clang-tidy compliance.

C's ! operator, ||/&&, and ternary conditions return int, which triggers readability-implicit-bool-conversion when assigned to or used with bool fields. These macros centralize the casts so the workaround lives in one place and can be revisited if C23 or a future clang-tidy relaxation removes the need.

Macro Definition Documentation

◆ BOOL_TO_INT

#define BOOL_TO_INT (   b)    ((int)(b))

Convert a bool to int explicitly.

Use in ternary conditions, arithmetic expressions, and GPU uniform uploads where an int/GLint/int32_t is expected from a bool source.

◆ BOOL_TOGGLE

#define BOOL_TOGGLE (   lval)    ((lval) = ((!(lval)) != 0))

Toggle a bool lvalue (equivalent to x = !x).

!x returns int in C; direct assignment to bool triggers the check.

◆ INT_TO_BOOL

#define INT_TO_BOOL (   expr)    ((expr) != 0)

Convert an int expression to bool explicitly.

Use for external API returns (GLFW, OpenGL) and logical OR/AND chains assigned to a bool variable.