Re: [dev] [dwm][st] why use ints over bools?
Дана 24/06/20 10:24PM, sewn написа:
> Sure, but why?
It is part of the suckless coding style. Since st is a suckless
project, it follows the suckless coding style.
* * *
I can't speak for those who wrote the suckless coding standard, but
as a bystander, I can give this observation.
If the question is what is the reasoning behind not using `bool` (or,
more accurately, `_Bool`, since `bool` is a macro defined in stdbool.h)
type in suckless coding style:
- The result of logical operators, such as !, &&, || and relational
operators, such as <, <=, >, >= is explicitly int in C99 anyway
(check the actual text of the standard if you don't believe me), with
possible values 0 and 1
- The type of `expression` in:
if (expression) statement
if (expression) statement else statement
in C99 is "scalar" with value tested for 0 - if unequal, `statement`
following `if` is executed, if equal, statement following `else` is
executed.
Given that, why complicate code by introducing a separate, superfluous,
type? Major compilers, such as GCC and Clang/LLVM, are competent enough
to optimize for speed or size as needed anyway.
Every new iteration of C after C99 introduced more unnecessary cruft.
C99 is the best version, although it has its rough edges, one of which
is the _Bool type.
Received on Thu Jun 20 2024 - 23:53:45 CEST
This archive was generated by hypermail 2.3.0
: Fri Jun 21 2024 - 00:00:19 CEST