Changes for C++ correctness

Moves some struct definitions from .c files to types.h.  This is in
preparation for bigger changes.

Add some casts to clarify types.

In cmd-know.c, C++ does not like the swap macro, so do it by hand.