Portable C avoids assumptions the standard does not guarantee: the size of int or long, byte order, signedness of char, struct padding, and compiler extensions. Use fixed-width types from <stdint.h>, sizeof, size_t for sizes, and standard library functions. Isolate platform code behind #ifdef in small files.
Check these before relying on Portability in real programs.
endian
Byte order
Writing raw int values to files or sockets is not portable. Convert to a fixed byte order.
ext
Compiler extensions
Features like __attribute__ or #pragma pack may be unsupported elsewhere. Wrap them in macros.
Remember
Key Takeaways
Use <stdint.h>.
Do not assume sizes.
Isolate platform code.
One line: Portable C avoids assumptions the standard does not guarantee: the size of int or long, byte order, signedness of char, struct padding, and compiler extensions.
Frequently Asked Questions
Stick to the C standard, use fixed-width integer types, avoid assumptions about sizes and byte order, and compile with -std=c11 -Wall -Wextra -Wpedantic on several compilers.
It is implementation-defined. Use signed char or unsigned char (or uint8_t) when the signedness matters.
Continue with "UTF-8 in C" next. Handle UTF-8 text as bytes: byte length versus character count. The C Advanced Concepts hub lists every topic in order.