Is C a portable language?

brown and black suitcase with red and yellow plastic toyI occasionally write answers on and many recurring questions are about assembly language. Now I used to write games in 6502 and Z80 assembly language when the only alternative was Basic. But assembly language is very tedious to write, painstaking and it’s slow to write programs in assembly language. Most of your code is moving values between memory and registers or vice versa.

Anything major you write will not easily port onto a different CPU or Operating System. A Mac uses a different CPU to most Windows PCs and a Raspberry Pi uses a similar CPU design to a Mac (M1 or M2) but there are still differences in calling OS routines on Raspberry Pi OS (based on Debian) and Mac OS.

Higher level languages are generally portable. I’ve written C# code that runs on Linux and my game which was 2,200 lines of C needed about an hours work to run on Ubuntu Linux and Raspberry Pi.

But if you have a large complex C application, it may have issues when porting it.  A developer Rex Jaeschke wrote a book on portability and published it in 1989. He’s recently updated it and it’s available on Wikibooks.  It’s called Portability and the C language and is several hundred pages long. If you ever want to port C, it is very worthwhile reading. I’ve added a permanent link to the Link to C utilities page.


(Visited 30 times, 1 visits today)