Question: A book I am reading suggests compiling programs on the machines they are intended for to ensure there isn't any issues. One of the big reasons I wanted to learn C is because it (can be) compatible with all operating systems. I am using this one on linux. If compiling the program on the intended machine(s) is not an option, is there a procedure that can be followed to ensure the program will run perfectly regardless of what version of linux/bsd it is run on? Like a crib sheet of compatible functions for different O/S as well as different architectures, and how to deal with each difference to ensure compatability?

Answer: 
Use libraries intended to work cross platform. If you do need to do anything that is platform dependent, you will have to write code that accounts for all architectures/platforms you want your application to run on.

Specific platforms will have `#define X` to determine if that's what the code runs on, so you can `#ifdef X` to check a specific platform and then write your code inside that statement, do the same for each bit of platform specific code.
the standard C is portable, but as with all languages, anything outside memory management and very basic libraries that the languages went out of their way to include will not be portable.

This problem is there even in Java, as suppose you want to do something that is seemingly portable (like setting color of the console window to green, or red) would not be possible. 

Overall, example-book C tends to be very portable, or portable with very minor fixes (such as making explicit casting).