Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why did K&R make &&, || logical and &, | bitwise, not the other way around? [closed]

I know that == was chosen for equality and = for assignment because they thought that people did more assignment than checking for equality---but surely they didn't think that there would be more bit fiddling than boolean logic?

Why not go the other way around, with & and | being logical operators?

like image 351
Aaron Yodaiken Avatar asked May 30 '12 02:05

Aaron Yodaiken


People also ask

When did K realize he was a replicant?

July 4, 2049 Stelline informed K that it was illegal for real human memories to be implanted into replicants. She offered to analyze his memory and tearfully confirmed that it was real. Faced with this, K had an outburst as he exited the lab.

How did K know where Deckard was?

Deckard left the child in the care of a replicant freedom group and helped to scramble the birth records to protect her identity. He then went into hiding in Las Vegas. In 2049, his location was discovered by the replicant Blade Runner K, and he was captured by the Wallace Corporation.

Is Deckard's daughter a replicant?

Biography. Stelline was born on June 10, 2021, the daughter of former Blade Runner Rick Deckard and Rachael, a Nexus-7 replicant, making her the first replicant-born child.

Why did Officer K have the memory?

How did Officer K get one of Ana's memories? His memory of hiding the wooden horse from the gang of boys at the orphanage is what leads K to initially believe that he his Deckard and Rachael's child, but as we eventually find out, it's actually Ana's memory which has been implanted in him.


1 Answers

From the horse's mouth:

Rapid changes continued after the language had been named, for example the introduction of the && and || operators. In BCPL and B, the evaluation of expressions depends on context: within if and other conditional statements that compare an expression's value with zero, these languages place a special interpretation on the and (&) and or (|) operators. In ordinary contexts, they operate bitwise, but in the B statement

    if (e1 & e2) ...
the compiler must evaluate e1 and if it is non-zero, evaluate e2, and if it too is non-zero, elaborate the statement dependent on the if. The requirement descends recursively on & and | operators within e1 and e2. The short-circuit semantics of the Boolean operators in such `truth-value' context seemed desirable, but the overloading of the operators was difficult to explain and use. At the suggestion of Alan Snyder, I introduced the && and || operators to make the mechanism more explicit.

Remember that C wasn't created in a vacuum; much of its weirdness can be traced to BCPL and B.

like image 52
John Bode Avatar answered Sep 19 '22 10:09

John Bode