Function Pointers and Callbacks: Sort, Search, Destroy
Post 7 of the Dynamic Arrays in C series · Full source code on GitHub Passing Behavior as Data Our array can store any type, grow on demand, handle errors without corrupting state, and communicate failures through typed error codes. What it cannot do is anything interesting with the elements inside it. We can push, get, set, and insert, operations that treat the elements as opaque byte blobs. We can’t sort the array because sorting requires knowing how to compare two elements. We can’t search it because searching requires knowing what “matching” means. We can’t even destroy it properly when the elements own heap-allocated resources, because the array doesn’t know how to clean them up. ...