liveBook · Manning

Portability

As explained in Modern C, Third Edition

Portability is the ability of software to operate across different platforms or computer architectures with little or no change.

Portability is the ability of a C program to operate across different platforms or computer architectures with little or no source change. C achieves this by abstracting over machine-specific languages, while compilation produces platform-dependent binary code. section 1.2 section 1.3

One source, different targets

The same getting-started.c source can be compiled for a particular target with a C compiler, such as c17 -Wall -o getting-started getting-started.c -lm. The compiler translates the source into executable code suited to that platform; the source remains the portable artifact. section 1.2

TAKEAWAY

  • Write correct C programs to preserve portability across platforms. section 1.2
  • Do not treat successful execution on one platform as proof of portability. section 1.2
  • Account for standards conformance and avoid extensions that are not widely portable. section 1.2
  • Listen to compiler warnings and correct diagnosed validity problems before relying on a program. section 1.3
 > clang -std=c2x -Wall -lm -o getting-started getting-started.c
 > gcc -std=c2x -Wall -lm -o getting-started getting-started.c
 > icc -std=c2x -Wall -lm -o getting-started getting-started.c

Compare compiler invocations for clang, gcc, and icc while targeting the C2x language mode and enabling warnings. section 1.2

Diagnostics expose nonportable assumptions

A flawed program using void main, an undeclared printf, and return 0 receives warnings from gcc and errors from clang. Correcting each diagnostic demonstrates that compiler acceptance differs and that portable C depends on valid, standard-conforming code. section 1.2 section 1.3

How Modern C, Third Edition covers it

How deep it goes
Explains source abstraction, platform-dependent binaries, standards conformance, and compiler diagnostics, but not portability internals.
Examples
Uses compiler commands, a flawed C listing, contrasting gcc and clang diagnostics, and stepwise correction exercises.
What it assumes
Assumes basic C source and compiler familiarity while establishing compilation, platform dependence, and portability from the beginning.
What you can do after
Apply it via a C compiler by writing correct code, comparing diagnostics, and testing compilation across platforms.
How it connects
Connects portability with C compilation, compilers, computer architectures, binary code, standards conformance, and compiler warnings.

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, Third Edition. The section links point to the parts of the book it draws on.