Learn C
#include "advanced/portability.h"

Portable C & Compiler Warnings

#concept

Portable C runs correctly on every conforming implementation — same output on GCC/Clang/MSVC, 32- and 64-bit, little- and big-endian. The practices: fixed-width stdint.h types for layout-sensitive data, no reliance on signed overflow or evaluation order, explicit sizes in I/O (%zu, not %d), and feature-test macros for platform code.

Warnings are the enforcement arm: -Wall -Wextra -Werror plus -pedantic turns assumptions into build failures, while -Wconversion and -Wshadow audit narrowing and hiding. Portable code plus maximal warnings is the closest C gets to a safety net.

#how it works
1

Types that travel

int32_t/uint64_t for layouts and protocols; plain int/long only where the platform genuinely decides.

2

No UB dependence

Never rely on overflow wraparound, evaluation order (f(i++, i)), or null arithmetic — all vary by compiler.

3

Warnings as errors

-Wall -Wextra -Werror -pedantic in every build — new warnings break the build the day they appear.

4

Audit extras

-Wconversion (narrowing), -Wshadow (hiding), -Wsign-compare (mixed signs) — enable per project, fix deliberately.

#example
#include <stdio.h>
#include <stdint.h>
 
int main(void) {
int32_t a = 2000000000;
int64_t b = (int64_t)a * 2;
printf("%lld\n", (long long)b);
return 0;
}
Output
4000000000
1int32_t pins 32 bits on every platform — the value fits with room to spare.
2Casting to int64_t before doubling keeps the math 64-bit; without it, int overflow would strike first.
34000000000 prints — portable width plus pre-widening beats platform luck.
#use cases
Libraries and tools shipping on multiple compilers and OSes
Warning-clean builds enforced with -Werror in CI
Fixed-width types in every serialized and wire format
Auditing narrowing, shadowing, and sign mixes with dedicated flags

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C yourself — building beats watching.