liveBook · Manning

Portability

As explained in Modern C

Portability is the property of software being usable across different computing environments with little or no modification.

A C source file can be compiled into different target binaries for a PC, phone, set-top box, or other platform. Portability is the property that lets one correct C program work across those environments with little or no modification. section 1.2

Compile the same program with different toolchains

The source file getting-started.c can be compiled with c99, clang, gcc, or icc. Each compiler translates the C program for the platform on which it runs; options such as -Wall request warnings, while -o names the executable. section 1.2

0   > clang -Wall -lm -o getting-started getting-started.c
1   > gcc -std=c99 -Wall -lm -o getting-started getting-started.c
2   > icc -std=c99 -Wall -lm -o getting-started getting-started.c


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":1}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":1}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":1}]]"}
!@%STYLE%@!

Compare equivalent clang, gcc, and icc commands for compiling the same C source. section 1.2

TAKEAWAY: Correct C programs are intended to be portable, but compiling and testing on one platform cannot guarantee portability. Some platforms do not conform to current standards, and extensions may not be widely portable. Treat compiler warnings as evidence that the program may need correction. section 1.2 section 1.3

How Modern C covers it

How deep it goes
Defines portability through platform-dependent binaries and compiler translation, but defers detailed portability rules.
Examples
Uses PC, phone, set-top box, and refrigerator examples plus c99, clang, gcc, and icc compilation commands.
What it assumes
Assumes basic C source and compilation concepts while introducing platform dependence and compiler translation.
What you can do after
Evaluate portability by writing correct C, compiling with warnings, and avoiding assumptions validated only on one platform.
How it connects
Connects portability with C, compilers, target platforms, standards conformance, and POSIX systems.

Also explained in

Compare how 5 books explain portability →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.