implementing some high order functions in C