A Complete Guide to Correct, Portable and Professional C Code
Introduction: Why C Still Demands Mastery
- What This Book Covers
- Prerequisites and Approach
- Standards Coverage
- How to Use This Book
Chapter 1: The C Language and Its Standards
- Why C Still Matters
- The ISO/ANSI Standardization Story
- Standards, Implementations and Extensions
- Portability as a First-Class Concern
- How to Read This Book
Chapter 2: The Compilation Model and Program Structure
- From Source to Executable
- Translation Units and Compilation
- Linkage and Symbol Resolution
- The Preprocessing Pipeline
- Building with Modern Toolchains
Chapter 3: Lexical Elements and the Basics of Syntax
- Tokens and Whitespace
- Identifiers and Naming Conventions
- Integer Literals and Numeric Constants
- Character and String Literals
- Operators and Precedence
Chapter 4: Types and Declarations
- The Type System Overview
- Signed and Unsigned Integer Types
- Floating-Point Types
- The void Type and _Bool
- Declaration Syntax Decoded
Chapter 5: Expressions, Operators and Evaluation Rules
- Expression Categories
- Sequence Points and Evaluation Order
- Integer Conversions and Promotions
- Signed Arithmetic, Overflow and Wraparound
- Pointer Expressions and Comparisons
Chapter 6: Control Flow and Statements
- Blocks, Scope and Compound Statements
- Conditional Execution
- Iteration and Loops
- Jump Statements
- Compound Literals and Designated Initializers
Chapter 7: Functions and Modular Design
- Function Declarations and Definitions
- Parameter Passing and Return Values
- Error Handling Strategies
- API Design Principles
- Building Reusable Modules
Chapter 8: Scope, Storage Duration and Linkage
- Scopes
- Storage Durations
- Linkage
- The static Keyword Explained
- Thread-Local Storage and _Thread_local
Chapter 9: Pointers and Pointer Arithmetic
- What a Pointer Is
- The Address-of and Indirection Operators
- Pointers and Arrays
- Pointer Arithmetic Rules
- Function Pointers and Callbacks
Chapter 10: The Memory Model and Object Representation
- Objects, Values and Representation
- Alignment and Padding
- Strict Aliasing and Type-Based Alias Analysis
- Object Lifetime
- Pointer Provenance and Validity
Chapter 11: Dynamic Memory Management
- The Allocation Functions
- Ownership and Responsibility
- Common Mistakes and Vulnerabilities
- Custom Allocators and Pools
- Memory Leak Detection and Debugging
Chapter 12: Data Structures and Generic Programming
- Dynamic Arrays
- Linked Lists and Variants
- Stacks and Queues
- Hash Tables
- Generic Programming Techniques
Chapter 13: Structures, Unions, Enumerations and Bit Fields
- Structure Types and Layout
- Unions and Type Punning
- Enumerations
- Bit Fields
- Design Patterns with Aggregates
Chapter 14: The Preprocessor, Macros and Header Design
- Macro Fundamentals
- Dangerous Macro Patterns
- Header File Best Practices
- Conditional Compilation and Configuration
- X-Macros and Metaprogramming
Chapter 15: The Standard Library - Core Facilities
- Diagnostics and Assertions
- Integer Types and Limits
- Character Handling and Classification
- String Functions
- Memory Operations
Chapter 16: The Standard Library - I/O, Time and Mathematics
- Formatted Output
- Formatted Input
- File Operations
- Time and Date Facilities
- Mathematics and Utilities
Chapter 17: Concurrency - Threads, Atomics and Synchronization
- The C11 Thread Library
- Atomic Operations and Memory Ordering
- The C Memory Model for Concurrency
- Portable Concurrency Alternatives
Chapter 18: Undefined Behavior and Defensive Programming
- What Undefined Behavior Really Means
- Catalog of Common UB Sources
- Unspecified and Implementation-Defined Behavior
- Static Analysis and Sanitizers
- Defensive Programming Patterns
Chapter 19: Security, Portability and Professional Engineering
- Common Security Vulnerabilities
- Portability Hazards and Solutions
- Debugging Techniques
- Testing and Quality Assurance
- Performance Profiling and Optimization
Conclusion: The Craft of Modern C
- A Language That Earns Its Power
- Principles for Writing Excellent C
- The Future of C
- A Final Word