small modifications so that this will work with C++ also
#ifdef __cplusplus added for use in .mm or C++ files