7 ms·
Uh... This is serious landmine... I suggest author to change this.
by stiray 7y ago
Uh... This is serious landmine... I suggest author to change this.
- shakna 7y agoThis particular code isn't about the post. It's about Bournegol, which doesn't actually exist anymore, and is actually quite hard to track down any examples of.
- kick 7y agoIt's...not, though? The Bourne Shell was released under a free license years ago along with the rest of v7, and it's just a macro hack. Very much still exists, and pretty easy to find. https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh
- thrwaway69 7y agoCan you explain why?
- Tervis 7y agoOn C language an expression which evaluates to any non-zero value is considered as True. So for example this kind of statement would not likely behave as intended: if (TRUE == expression) { ... }
- Koshkin 7y agoI have refused to hire people who did this. (FALSE, too, even though it is safer.)
- shakna 7y agoTo emphasise: This is about Bournegol. Nothing to do with this post. > Can you explain why? Because it isn't how most C libraries expect true/false to be defined. stdbool in C99 standardized things a bit, but before then what was generally accepted was: > true is 1 > false is !true (Often 0 in practice). Which means that any trivial: if(true) { ... } Won't work under Bournegol. Instead you _need_ to compare when doing an if statement. So the C-programmer is easily tripped up. False will work as expected, but True won't... All the time. There may be times it does work. Leaving the programmer throwing their hands in the air.
- thrwaway69 7y agoAh. Thanks for the explanation.
- kaetemi 7y agoMost cases I've seen accept anything as true as long as the LSB is 1, and quite strictly 0 as false. Everything else is up in the air. The value -1 is definitely true. :)
- ufo 7y agoOne could say that -1 is the truest true, because its two's-complement representation has the most 1s.
- kaetemi 7y agoTrue.
- shakna 7y ago> The value -1 is definitely true Except when being used as a comparison to any of the std utilities.
- syockit 7y agoAs far as I know, std library specifically uses the word "nonzero" in the documentation to denote non-false value. Therefore you should be using !, &&, || for any boolean ops, but never == nor !=
- wbl 7y agoAny nonzero integer is considered true in that expression, so if(TRUE) still works.
- Hello71 7y agothis is utter nonsense. in C, since before C89, all non-zero values are considered true in conditional contexts (if, for, while, ?:). http://port70.net/~nsz/c/c89/c89-draft.html#3.6.4.1 http://port70.net/~nsz/c/c89/c89-draft.html#3.6.4.1. false must therefore be exactly zero. !1 is also always 0, as it must be. http://port70.net/~nsz/c/c89/c89-draft.html#3.3.3.3 http://port70.net/~nsz/c/c89/c89-draft.html#3.3.3.3.
- kick 7y agoThe author is 76, and retired. This is from UNIX v7, before the standardization of C.
- mst 7y agoDon't bash it til you understand it.