Write exit function, change back to #defines

Basic exit function structure written, and swapped back to the #define
style of writing, because while it isn't as typesafe, it stops clang
generating warnings when using the globals in static array initialisations.