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




