Useful helper functions in c and c++