5 ms·
You don't need to check !!indirect. There is no cases that the indirect pointer is NULL: while (!!(*indirect) && (*indirect) != entry) indirect = &(*indi
by kbumsik 6y ago
You don't need to check !!indirect. There is no cases that the indirect pointer is NULL:
while (!!(*indirect) && (*indirect) != entry)
indirect = &(*indirect)->next;
Also I would rather use * indirect instead of !!(* indirect).
- cmroanirgo 6y agocorrect. I was just being overly pedantic
- muro 6y agoWhy the !! ? I thought that only makes sense in JS.
- cmroanirgo 6y agoI'm not sure about the current state of compiler optimisations, but IIRC in the olde-days, a not not in an if() statement would assemble to JZ, saving a clock cycle (& an opcode?), and wouldn't need to stall to load in the full width of the register. Today's branch predicting compilers are beyond me. I still use it as a clarification that it's a deliberate boolean operation, rather than implicit.
- user-the-name 6y agoI highly doubt that any modern compiler would generate different code with or without the !!. Not even sure why an old compiler would do that? It's the exact same semantics, surely.
- nitrogen 6y agoI thought that only makes sense in JS. In C any nonzero value is considered "truthy", and on most architectures NULL is defined to be (void * )(0) or similar. The logical not operator AKA bang operator will replace truthiness with 0, and falsiness with 1. So applying it twice collapses all nonzero values to 1.
- user-the-name 6y agoWell, yes, but that does absolutely nothing in this code, as it is immediately used as the argument to an if statement.
- nitrogen 6y agoIndeed, I was only commenting on the JS vs C part.
- eps 6y agoThat had nothing to do with pedantry.