Skip to content

SpeyTech/c-from-scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

C From Scratch

Learn to build safety-critical systems in C.

Not "Hello World". Real kernels. Mathematical rigour. Zero dependencies.

"Math β†’ Struct β†’ Code β†’ Test"


πŸ“˜ The Book

C From Scratch Book Cover

C From Scratch: Learn Safety-Critical C the Right Way

The complete guide to writing C that doesn't just work β€” it provably works.

What you'll learn:

  • The MATH β†’ STRUCT β†’ CODE β†’ TEST methodology
  • Fixed-width integers and why int kills rockets (Ariane 5)
  • Contracts, preconditions, and invariants
  • State machines that can't enter invalid states
  • Memory safety without garbage collection
  • The path from learning to DO-178C / IEC 62304 / ISO 26262 certification

What you won't find:

  • "It works on my machine"
  • Undefined behaviour swept under the rug
  • malloc in safety-critical code
  • Tutorials that teach bad habits

πŸ“– Buy the book on Leanpub β†’


Philosophy

Most tutorials teach you to write code that seems to work.
This course teaches you to write code that provably works.

The method:

  1. Define the problem mathematically
  2. Prove correctness formally
  3. Design structs that embody the proof
  4. Transcribe the math into C
  5. Test against the contracts
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    THE APPROACH                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                             β”‚
β”‚   Problem  ──►  Math Model  ──►  Proof  ──►  Structs        β”‚
β”‚                                                β”‚            β”‚
β”‚                                                β–Ό            β”‚
β”‚                           Verification  ◄──  Code           β”‚
β”‚                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The Seven Foundation Modules

Module Question Role Tests
Pulse Does it exist? Sensor βœ“
Baseline Is it normal? Sensor 18/18
Timing Is it regular? Sensor βœ“
Drift Is it trending toward failure? Sensor 15/15
Consensus Which sensor to trust? Judge 17/17
Pressure How to handle overflow? Buffer 16/16
Mode What do we do about it? Captain 17/17

Plus: Integration Example β€” All modules working together.


The Safety Stack

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MODULE 7: MODE MANAGER                           β”‚
β”‚                       "The Captain"                                 β”‚
β”‚   Decides: What mode? What actions allowed?                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↑
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MODULE 6: PRESSURE                               β”‚
β”‚                       "The Buffer"                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↑
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MODULE 5: CONSENSUS                              β”‚
β”‚                       "The Judge"                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↑
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό                   β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   CHANNEL 0     β”‚ β”‚   CHANNEL 1     β”‚ β”‚   CHANNEL 2     β”‚
β”‚  Pulse β†’ Base   β”‚ β”‚  Pulse β†’ Base   β”‚ β”‚  Pulse β†’ Base   β”‚
β”‚  β†’ Timing       β”‚ β”‚  β†’ Timing       β”‚ β”‚  β†’ Timing       β”‚
β”‚  β†’ Drift        β”‚ β”‚  β†’ Drift        β”‚ β”‚  β†’ Drift        β”‚
β”‚   "Sensors"     β”‚ β”‚   "Sensors"     β”‚ β”‚   "Sensors"     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Properties

Every module is:

  • Closed β€” No external dependencies at runtime
  • Total β€” Handles all possible inputs
  • Deterministic β€” Same inputs β†’ Same outputs
  • O(1) β€” Constant time, constant space
  • Contract-defined β€” Behaviour is specified, not implied

Getting Started

# Clone
git clone https://github.com/SpeyTech/c-from-scratch.git
cd c-from-scratch

# Try any module
cd projects/pulse
make && make test && make demo

# Or run the full integration
cd projects/integration
make run

Start with Pulse Lesson 1: The Problem.


Specification

See SPEC.md for the complete framework specification:

  • Core principles
  • Module structure
  • Contract definitions
  • Composition rules
  • Certification alignment (DO-178C, IEC 62304, ISO 26262)

Related Projects

This course is part of the SpeyTech ecosystem for deterministic, certifiable systems:

Project Description
Fixed-Point Fundamentals Free course on fixed-point arithmetic
certifiable-* Deterministic ML pipeline with cryptographic verification
C-Sentinel Semantic security monitoring in pure C

Who This Is For

  • Developers building safety-critical software
  • Systems programmers who want provable correctness
  • Students learning C the rigorous way
  • Anyone tired of "it works on my machine"

Prerequisites

  • Basic C syntax (variables, functions, structs)
  • Comfort with command line
  • Willingness to think before coding

Author

William Murray β€” 30 years UNIX systems engineering

License

MIT β€” See LICENSE


"Sensors report. The Captain decides."

πŸ“˜ Buy the Book Β· 🌐 SpeyTech Β· πŸ’» GitHub

About

Learn to build safety-critical systems in C. Prove first, code second.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages