Split into C and C++ versions