refactor headers, especially alltypes.h, and improve C++ ABI compat