by antirez · 14y ago · 0 comments
1) // style commands are C99 only. If you don't have other C99 dependencies it's somewhat a shame it could not compile in older systems just for this.
2) inline should rarely be used if not into performance critical code.
3) two space indent is not C-ish ;)
4) While 'bool' is valid C99 code, it is more or less never used in C code.
I disagree. It's used quite a bit in the code I work on. Little things like an explicit statement that this variable is only true or false significantly reduce the cognitive load when reading code.
Anyway, even if it were true that nobody uses bool, there's absolutely no reason to discourage its use.
Since it's allowed to use bool in arithmetic context (some_int + some_bool will compile fine, for example), having a bool type is useless. (Useless in C and C++ that is; Java, for example, has sane bool handling.)
I have no idea why C99 introduced _Bool type when they could have just inserted typedef char bool; in stdbool.h. Has anybody ever used for something useful the fact that memory representation of _Bool is constrained to read as 0 or 1?
2. C lets you commit all kinds of atrocities in arithmetic contexts with or without it.
3. Having a standard typedef saves us from all having to make our own
4. None of your points support the case of "don't use stdbool"
Huh? I was saying that the language did not have to be extended to get a bool typedef. C99 defines a new type, _Bool (name from the reserved identifier space), which is different from existing types. stdbool is a simple typedef of _Bool to bool.
Also, introducing bool would have had meaning if implicit conversion to int wasn't allowed. But since it is, it's a useless type.
My viewpoint is that types exist for enforcing semantic constraints; what use of a bool type that allows performing semantically nonsense operation, such as implicit conversion to int in arithmetic context? The C99 committee messed it up big with bool.
Are people using such a wide range of font sizes, and font aspect ratios, that 4 spaces doesn't make sense for everyone?
problem solved ;-)
But I'm also a single-return fetishist, so I tend to nest deeper than normal.