C Portability Lessons from Weird Machines
A lot of the &quot;weird machines&quot; for C are microcontrollers and the like; the 8051 is mentioned, but another big &quot;C-hostile&quot; MCU family is the Microchip PIC, which still has its own C compiler. DSPs are another category where unusual word sizes are common (24 bits for char&#x2F;short&#x2F;int is often encountered.)<p><i>It’s amazing that, by carefully writing portable ANSI C code and sticking to standard library functions, you can create a program that will compile and work without modification on almost any of these weird systems.</i><p>The big question, which I ask whenever someone harps on about portability, is <i>does it even make sense</i>? Is your average PC&#x2F;smartphone application realistically ever going to be ported to a 6502 or a Unisys mainframe? Keep in mind that I&#x2F;O in particular is going to differ significantly, and something like standard input might not even exist (think of a fixed-function device like an oven controller with only a few buttons and LEDs for I&#x2F;O.) I don&#x27;t think it&#x27;s particularly amazing, because the &quot;core&quot; of C essentially represents all the functionality of a stored-program digital computer; so if you completely ignore things like I&#x2F;O it&#x27;s not hard to see how the same piece of code can express the same concepts on <i>any</i> of the latter type of computer.<p>It should also be noted that these &quot;weird&quot; environments are often not &quot;strictly conforming&quot; either, because it&#x27;s either impossible or doesn&#x27;t really make sense to. Besides the &quot;omissions&quot; they will also have &quot;extensions&quot; that help the programmer to more fully utilise the platform&#x27;s capabilities.