| ▲ | random_human_ 4 days ago | ||||||||||||||||||||||
Is foo a pointer in your example? Is free(NULL) not a valid operation? | |||||||||||||||||||||||
| ▲ | rstuart4133 4 days ago | parent [-] | ||||||||||||||||||||||
Yes `foo` is a pointer. `free(NULL)` is harmless in C89 onwards. As I said, programmers freeing NULL caused so many issues they changed the API. It doesn't help that `malloc(0)` returns NULL on some platforms. If you are writing code for an embedded platform with some random C compiler, all bets on what `free(NULL)` does are off. That means a cautious C programmer who doesn't know who will be using their code never allows NULL to be passed to `free()`. In general, most good C programmers are good because they suffer a sort of PTSD from the injuries the language has inflicted on them in the past. If they aren't avoiding passing NULL to `free()`, they haven't suffered long enough to be good. | |||||||||||||||||||||||
| |||||||||||||||||||||||