News for hackers. Stuff that matters.
Re:Let's Destroy C by stiray on Thursday January 30, 2020 @01:41AM (#22189388)
Uh... This is serious landmine... I suggest author to change this.
Re:Let's Destroy C by shakna on Thursday January 30, 2020 @01:43AM (#22189395)
This 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.
Re:Let's Destroy C by kick on Thursday January 30, 2020 @10:07AM (#22191779)
It'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

Re:Let's Destroy C by kick on Thursday January 30, 2020 @10:07AM (#22191773)
The author is 76, and retired. This is from UNIX v7, before the standardization of C.
Re:Let's Destroy C by mst on Thursday January 30, 2020 @01:51PM (#22194120)
Don't bash it til you understand it.
Re:Let's Destroy C by thrwaway69 on Thursday January 30, 2020 @01:47AM (#22189416)
Can you explain why?
Re:Let's Destroy C by Tervis on Thursday January 30, 2020 @02:03AM (#22189491)
On 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)
    {
        ...
    }
Re:Let's Destroy C by Koshkin on Thursday January 30, 2020 @09:25AM (#22191445)
I have refused to hire people who did this. (FALSE, too, even though it is safer.)
Re:Let's Destroy C by shakna on Thursday January 30, 2020 @02:04AM (#22189492)
To 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.

Re:Let's Destroy C by wbl on Thursday January 30, 2020 @07:27AM (#22190856)
Any nonzero integer is considered true in that expression, so if(TRUE) still works.
Re:Let's Destroy C by kaetemi on Thursday January 30, 2020 @03:39AM (#22189864)
Most 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. :)
Re:Let's Destroy C by ufo on Thursday January 30, 2020 @10:14AM (#22191843)
One could say that -1 is the truest true, because its two's-complement representation has the most 1s.
Re:Let's Destroy C by kaetemi on Friday January 31, 2020 @05:32AM (#22200581)
True.
Re:Let's Destroy C by shakna on Thursday January 30, 2020 @10:56AM (#22192263)
> The value -1 is definitely true

Except when being used as a comparison to any of the std utilities.

Re:Let's Destroy C by syockit on Thursday January 30, 2020 @05:00PM (#22196241)
As 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 !=
Re:Let's Destroy C by Hello71 on Thursday January 30, 2020 @02:00PM (#22194235)
this 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. 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.
Re:Let's Destroy C by thrwaway69 on Thursday January 30, 2020 @02:18AM (#22189542)
Ah. Thanks for the explanation.