Skip to content

Embedded Headers

Derek Snider edited this page Jul 23, 2026 · 2 revisions

Embedded Headers

madc includes 40+ standard C/POSIX headers baked into the binary. No external header files needed at runtime.

Usage

#include <stdio.h>      // angle brackets check embedded headers first
#include <math.h>
#include <string.h>
#include <iostream>

Auto-header inclusion

For common library symbols you can skip the #include entirely — madc knows which embedded header declares which identifier and inserts the header automatically when it sees the symbol:

int main() {
    printf("no include needed: %s\n", "yes");   // <stdio.h> auto-included
    return 0;
}

This is what makes one-liners and script mode feel like a scripting language while staying real compiled C. Explicit #includes always work and always take precedence — auto-inclusion only fills in what you left out.

Key headers

<stdio.h>

Standard I/O constants and functions:

#include <stdio.h>

int main() {
    printf("Hello %s, you are %d years old\n", "Alice", 30);
    return 0;
}

Constants: EOF, SEEK_SET, SEEK_CUR, SEEK_END, BUFSIZ, NULL

<math.h>

Auto-loads libm. Provides math constants and functions:

#include <math.h>

int main() {
    double x = sqrt(16.0);       // 4.0
    double y = pow(2.0, 10.0);   // 1024.0
    double z = sin(M_PI / 2);    // 1.0
    return 0;
}

Constants: M_PI, M_E, M_SQRT2, INFINITY, HUGE_VAL, and more.

Functions: sqrt, sin, cos, tan, pow, exp, log, floor, ceil, round, fabs, fmod, hypot, and more.

<iostream>

C++ streams:

#include <iostream>

int main() {
    cout << "Hello, world!" << endl;
    string name;
    cin >> name;
    return 0;
}

Registers cout, cin, cerr, endl via lazy initialization.

How it works

Header files in include/madc/ are converted to C++ string literals at build time by scripts/gen_embedded_headers.sh. They're compiled into the madc binary — no filesystem lookup needed.

When you #include <header.h>, madc checks embedded headers first. Constants are processed via #define. Functions are available through the dlsym fallback — any function in a loaded shared library (libc is always loaded, libm after #include <math.h>) is callable without explicit registration.

Available headers

Headers include standard C (stdio.h, stdlib.h, string.h, math.h, ctype.h, time.h, errno.h, etc.), POSIX (unistd.h, fcntl.h, sys/stat.h, sys/file.h, dirent.h, etc.), and C++ (iostream).

What's next?

Clone this wiki locally