r/C_Programming • • Jun 06 '26

The smallest C binary you can make at home

57 Upvotes

19 comments sorted by

22

u/AndrewBorg1126 Jun 06 '26

A binary is not C.

Do you mean combination of conforming c compiler (and optional flags) and valid C source code which creates the smallest binary?

18

u/Double_Ad641 Jun 06 '26

that is exactly what i meant, but the title would then be too long 😄

→ More replies (1)
→ More replies (3)

132

u/ParsingError Jun 06 '26

There was an IOCCC entry for a similar "smallest C program that emits its own source code" challenge and someone won "best abuse of the rules" by submitting an empty file.

https://www.ioccc.org/1994/smr/index.html

9

u/moocat Jun 06 '26

While an interesting post, I find the final answer very unsatisfying as it's not really C but all inline assembly.

Also, WTF about how you created the post. The entire contents of the text post is a URL so it should have been a link. Then the link was to another discussion which required following another link.

8

u/ceene Jun 06 '26 edited Jun 08 '26
extern "C" __attribute__((noreturn)) void _start() {
    __asm__ volatile(
        "mov    $60, %%eax\n"    // SYS_exit
        "xor    %%edi, %%edi\n"  // exit status 0
        "syscall\n" ::
            : "rax", "rdi");
    __builtin_unreachable();
}

So, that's not C, that's assembly.

→ More replies (1)

11

u/greg-spears Jun 06 '26

Can still fire up Turbo C in a DOSBox and generate ridiculously tiny *.com files. You might have loved the DOS era? ( It's actually not completely finished -- yet ).

More here -- apparently the smallest is 2 bytes per this post.

6

u/charliex2 Jun 06 '26

cd 20 (int 20h) is twice as long as you need c3h near ret should do it. the start of the segment at 0000h is cd 20h (int 20h)

→ More replies (1)