Skip to content

Your First Program

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

Your First Program

Hello, world

Create a file called hello.mad:

#include <stdio.h>

int main() {
    printf("hello, world\n");
    return 0;
}

Run it:

madc hello.mad
hello, world

That's it. No Makefile, no compile step, no link flags. madc JIT-compiles your code directly to native machine code and runs it.

Looks familiar? It should — this is valid C. madc understands C syntax, C headers, and C library functions out of the box.

Using C++ features

madc also supports C++ streams, strings, and more. Create greet.mad:

#include <iostream>

int main() {
    std::string name = "World";
    std::cout << "Hello, " << name << "!" << std::endl;

    for (int i = 1; i <= 3; i++) {
        std::cout << i << std::endl;
    }

    return 0;
}
madc greet.mad
Hello, World!
1
2
3

Using namespace functions

Here's where madc gets interesting. Create demo.mad:

#include <iostream>

int main() {
    // PHP-style string operations
    std::string csv = "charlie,alice,bob";
    std::string delim = ",";
    array names;
    php::explode(names, delim, csv);
    php::sort(names);

    std::string sorted;
    php::implode(sorted, delim, names);
    std::cout << sorted << std::endl;

    // Python-style title case
    std::string title = "hello world";
    python::title(title);
    std::cout << title << std::endl;

    // Rust-style string functions
    std::string s = "  padded  ";
    rust::trim(s);
    std::cout << "[" << s << "]" << std::endl;

    return 0;
}
madc demo.mad
alice,bob,charlie
Hello World
[padded]

No imports. No package manager. These functions are built into madc across six language namespaces.

Making it executable

Add a shebang line and make the file executable:

#!/usr/bin/env madc
#include <stdio.h>

int main() {
    printf("I'm a script!\n");
    return 0;
}
chmod +x script.mad
./script.mad

Compiling to a native executable

Generate a standalone binary:

madc -o hello hello.mad
./hello

The output is a native Linux ELF executable — no runtime dependency on madc.

See Native Executables for more details.

What's next?

Clone this wiki locally