5 ms·
> && and || (which mimics & and |) I've always thought of it as mimicking * (multiplication) and + (addition), and you can actually use * and + in place of &&
by smcameron 3y ago
> && and || (which mimics & and |)
I've always thought of it as mimicking * (multiplication) and + (addition), and you can actually use * and + in place of && and || if you wanted to (not advisable, though the idea can be used in expressions to produce branchless code, common technique in GPU shader code). I used to use this trick in TI99/4a BASIC which lacked "AND" and "OR" in "IF" statements, but because boolean expressions evaluated to integer 1 and 0 for true and false, multiplication and addition could serve as AND and OR.
- teo_zero 3y agoBut remember that * and + don't short-circuit. This won't work: found = (p != NULL) * (*p ! = 0);