TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What is the simplest self-compiling subset of C?

4 pointsby sandinmyjointsabout 4 years ago
See https://github.com/certik/bcompiler/issues/1#issuecomment-793896926

2 comments

certikabout 4 years ago
Great question. Here are some candidates:<p>* <a href="https:&#x2F;&#x2F;github.com&#x2F;rswier&#x2F;c4" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rswier&#x2F;c4</a><p>* <a href="https:&#x2F;&#x2F;github.com&#x2F;Fedjmike&#x2F;mini-c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Fedjmike&#x2F;mini-c</a><p>* <a href="https:&#x2F;&#x2F;github.com&#x2F;rui314&#x2F;8cc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rui314&#x2F;8cc</a><p>* <a href="https:&#x2F;&#x2F;github.com&#x2F;rui314&#x2F;chibicc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rui314&#x2F;chibicc</a><p>* <a href="https:&#x2F;&#x2F;github.com&#x2F;aligrudi&#x2F;neatcc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;aligrudi&#x2F;neatcc</a><p>Some of them are actually interpreters, and I personally would be interested in actual compilers that generate machine code.
bloakabout 4 years ago
I think there are two aspects to &quot;simplest&quot; here:<p>1. You want a compiler that&#x27;s short and easy to understand.<p>2. You want a simple definition of what this subset of C is so someone using it knows what&#x27;s allowed and what isn&#x27;t even if the compiler doesn&#x27;t give helpful error messages and perhaps doesn&#x27;t even detect all errors.<p>The answer is probably something like C89 with no preprocessor and a simplified type system. Definitely no aggregate types (array, struct, union) and no pointers to functions. Remaining questions include:<p>* Are you happy with a 32&#x2F;64-bit char and sizeof(everything) == 1?<p>* Are you happy to lose the distinction between signed and unsigned types? If you have everything signed then it is hard to avoid undefined behaviour, and if you have everything unsigned then there&#x27;s a nasty mismatch with the prototype of main and standard library functions using int.<p>* If you do throw away the signed&#x2F;unsigned distinction, do you tell people to survive without &lt;, &lt;=, &gt;, &gt;=, or do you tell them to only compare signed (or only compare unsigned) values?