What about using char's then?
În 15 iunie 2024 15:36:16 EEST, "Mattias Andrée" <maandree_AT_kth.se> a scris:
>I have some general issues with _Bool:
>
>Arithmetic or bitwise operations on _Bool is subject to type promotion
>making them rather pointless.
>
>With also be a problem if they were not, as you than couldn't sum of _Bool's
>to find how many were set (commonly this we be to detect if more than 1 was
>set).
>
>It is implementation-define which signness _Bool has, meaning, I don't know
>if it will be promoted to a signed or an unsigned int.
>
>_Bool is only useful to make sure that a non-zero value is converted to the
>value 1. And if this is absolutely necessarily, you should make this explicit,
>e.g. with `!!x` or `x?1:0`. _Bool can introduce implicit and unnecessary
>overhead to ensure that the value is always 1 or 0. And despite all this,
>you can mess up and get _Bool's with a non-boolean value.
>
>It is implementation-defined how wide a _Bool is.
>
>_Bool will be at least the size of a byte, if you really want it to be a bit
>if you have many of them, you can use bit fields or good old names values to
>store multiple boolean values in one int. Generally you don't gain any real
>savings by using a single byte type instead of an int if you only one or two
>booleans.
>
>Basically, I like things to be explicit and well-defined.
>
>
>
>On Sat, 15 Jun 2024 11:54:02 +0000
>Zac <maczac_AT_protonmail.com> wrote:
>
>> In a number of spots in dwm and st I've seen the use of integers as booleans. e.g.
>> - dwm.c line 95, 140, 1870
>> - drw.c line 252
>> - st.c line 44, 48
>>
>> That's not an extensive list; just some examples.
>>
>> I'm curious why you use ints though. Because bools are 31 bits smaller than ints, which is 31 bits of memory saved. Not that 31 bits is very much, but still...
>>
>
>
--
Linux-gentoo-x86_64-Intel-R-_Core-TM-_i5-7400_CPU__AT__3.00GHz
COMMON_FLAGS="-O3 -pipe -march=native -ftree-vectorize -ffast-math -funswitch-loops -fuse-linker-plugin -flto -fdevirtualize-at-ltrans -fno-plt -fno-semantic-interposition -falign-functions=64 -fgraphite-identity -floop-nest-optimize"
USE="-* git verify-sig rsync-verify man alsa X grub ssl ipv6 lto libressl olde-gentoo asm native-symlinks threads jit jumbo-build minimal strip system-man"
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /lib/udev /usr/share/icons /usr/share/applications /usr/share/gtk-3.0/emoji /usr/lib64/palemoon/gtk2"
Received on Sat Jun 15 2024 - 16:05:27 CEST