4 ms·
>>> remembering to free(); not to free() twice; > You can set the pointer to NULL, then freeing again won't hurt >>> not to use after free() > Set the poi
by rrauenza 10y ago
>>> remembering to free(); not to free() twice;
> You can set the pointer to NULL, then freeing again won't hurt
>>> not to use after free()
> Set the pointer to NULL so it will crash.
I like C and think it is bashed too much, but double frees and invalid pointers are most often the result of multiple copies of the pointer... some other structure hanging onto the original reference.
- chelahmy 10y ago> some other structure hanging onto the original reference. Let's unleash the superpower of C. You should've been using pointers to a pointer so that it is always a single reference to a memory block. You can't really be programming in C if you're not thinking in pointers. One more thing; The article should have mentioned "pointer increment" which has nothing to do with "+= 1".
- kbp 10y ago> One more thing; The article should have mentioned "pointer increment" which has nothing to do with "+= 1". What do you mean? ++ptr is perfectly equivalent to ptr += 1, for any pointer type.
- deleted 10y ago[deleted]
- chelahmy 10y agoI read it as integer arithmetic. It is semantically different from pointer arithmetic.
- rrauenza 10y agoSo it's turt^H^H^H^Hpointers all the way down?
- chelahmy 10y agoWill the following help with the depth, or any depth? int *a, **b, **c, **d; d = c = b = &a;