3 ms·
Using bool in C, as well as C++ has distinct advantages. If Linus or some idiot cannot control himself from making mistakes, and from causing serious damage to
by altrego99 13y ago
Using bool in C, as well as C++ has distinct advantages. If Linus or some idiot cannot control himself from making mistakes, and from causing serious damage to the code, it is his fault. You can always aim it at your foot given any construction tool. I don't care if fools can't control it, but I wouldn't say no to bool.
- dchichkov 13y agoJust for a reference, how many decades of C experience are behind your comment? Nothing personal here, it is just one really need that information to put your reply into context.
- lucisferre 13y agoWhy?
- dchichkov 13y agoWell,... wanted to give OP a chance to put his/her comment into context. It is just some times, on HN, you really don't know what kind of experience is standing behind the comment.
- girvo 13y agoThis is the only forum I've ever been on where I can be presently surprised by how much experience actually is behind a statement. Its a nice change for once.
- fredsanford 13y agoSounds like someone with limited experience with OPC... (Other Peoples Code) Ever worked on a big code base where some programmers were in Vietnam, some in Russia, some in China and most here in the US? Conventions are different and pride and communications issues make it hard to correct behavior. Ever worked as the commit point for an offshore group? Code review? Didn't think so...
- primelens 13y agoWow, I'm sure there's plenty of things to vehemently disagree with Torvalds on and even to criticize him - manners, politics, management style and even the finer points of programming. But I would have thought he'd earned his stripes enough to at least not to be called an idiot on his C skills on HN. But apparently not. Next up, Dennis Ritchie!
- solistice 13y agoJust as inexperienced as this Kerningham guy. On the other hand, I'm happy if my C code compiles, so I shouldn't throw any stones here.
- reginaldjcooper 13y agoIf you have the option to choose between a hammer that will hit your own finger and one that will stop short when it detects that (with no false positives), all other considerations being the same; and you willingly choose the first hammer, you are a fool. Basically the true idiot is not one that makes mistakes, but one that assumes only idiots make mistakes.
- andrewcooke 13y agobut, from what i can tell, _Bool actually prevents mistakes. it works consistently and logically like a boolean type. the mistakes come from pre-C99 code that calls things boolean, but has unexpected dependencies (that _Bool removes) on bit-level structure. the more i learn from this thread, the more i want to use _Bool. which worries me, because Linus isn't dumb. but i think(?) the point he is making is related more to legacy code that is "broken but works". or maybe to programmers that rely on/use/exploit bit-structure/implementation details in "bool" types because they don't have experience with more strictly typed languages. [edit: or as mbell said in a reply to me elsewhere, because at os level you often do need to care about bits]
- to3m 13y agoI've certainly found C++ bool helpful, in terms of readability and self-documentation, and the general positive clarifying effects of making sure you've got your types straight (to the extent that C++ gives you any help with that). C++ bool does the right thing, as far as turning values into true or false goes (the cast effectively does a "!=0", making the result exactly 1 or 0). I believe that C99 _Bool behaves in the same way in this respect - so that would be doing the right thing too. (One issue with "native" bools, that others have pointed out, is that it's possible to introduce bugs due to implicit conversions. But I've personally found this behaviour usually to be what you want, and I don't remember having to fix any bugs caused by it, suggesting that they can't have been all that difficult to sort out.) His point about casting to fake bool types is well made, and I wonder how many instances of this I will now spot? (gcc appears to issue perfectly fine warnings for this case, though.) Another argument for using the built-in types, in my view. Or for switching to "typedef uintptr_t bool".
- EpicEng 13y agoInteresting that you fail to name any of these advantages.