fixing build errors with Clang C++ on Linux

* fixed invalid conversion by adding C casts. Also fixed the swap pointers thing with std::swap for C++.
* note: many more errors probably exist on the other platform files; I cannot
 test any of those now.