If this implementation had existed in the 1980s, the C standard would have a rule that different tokens hashing to the same 16-bit value invoke undefined behavior, and optimizing compilers in the 2000s would simply optimize such tokens away to a no-op. ;)
Oh, it looks like my X86-16 boot sector C compiler that I made recently [1]. Writing boot sector games has a nostalgic magic to it, when programming was actually fun and showed off your skills. It's a shame that the AI era has terribly devalued these projects.
Er, what? The article describes a compiler for a not-quite-C programming language which fits entirely in 512B. Your project, if I see this correctly, can optionally produce code meant to execute as boot sector.
Both interesting projects, but other than the words 'boot sector', 'C' and 'compiler', I don't see a similarity.
An interesting use case - for the compiler as-is or for the essentiall idea of barely-C - might be in bootstrapping chains, i.e. starting from tiny platform-specific binaries one could verify the disassembly of, and gradually building more complex tools, interpreters, and compiler, so that eventually you get to something like a version of GCC and can then build an entire OS distribution.
This is very nice. I'm currently writing a minimalist C compiler although my goal isn't fitting in a boot sector, it's more targeted at 8-bit systems with a lot more room than that.
This is a great demonstration of how simple the bare bones of C are, which I think is one reason I and many others find it so appealing despite how Spartan it is. C really evolved from B which was a demake of Fortran, if Ken Thompson is to be trusted.
Would and how much would it shrink when if, while, and for were replaced by the simple goto routine? (after all, in assembly there is only jmp and no other fancy jump instruction (I assume) ).
And PS, it's "chose your own adventure". :-)
I love minimalism.
This is the kind of project that reminds you how far removed modern development is from the actual machine. We pile abstractions on abstractions until "Hello World" needs 200MB of node_modules, and then someone fits a C compiler in 512 bytes.
Not saying we should all write boot sector code, but reading through projects like this is genuinely humbling. Great educational resource too.
It's a fun comparison, but with the notable difference that that one can compile the Linux kernel and generate code for multiple different architectures, while this one can only compile a small proportion of valid C. It's a great project, but it's not so much a C compiler, as a compiler for a subset of C that allows all programs this compiler can compile to also be compiled by an actual C compiler, but not vice versa.
I actually "shipped" a parser using the symbols' hash(as the only identifier) for a test tool once. Hopefully, the users never used enough symbols to collide 32-bits.
For me is not interesting because it fits in 512 bytes, it's interesting because it's very simple. I think it would be a great introduction to learning about compilers.
That would be true of one using a libc, but in a boot sector, you only have the bios, so the atoi being referenced is the one defined in c near the beginning of the article
Nice, now you can dd it to your boot sector and ... Wait, it is 2026, there are 1000 ways of booting and memory mapping on so-called unified ARM architecture @,@
layer8|22 days ago
RodgerTheGreat|22 days ago
xorvoid|22 days ago
mati365|22 days ago
[1] https://github.com/Mati365/ts-c-compiler
guenthert|21 days ago
Both interesting projects, but other than the words 'boot sector', 'C' and 'compiler', I don't see a similarity.
w4yai|22 days ago
Oh no. Now more people are able to do what I do. I'm not special anymore.
xorvoid|22 days ago
einpoklum|22 days ago
Examples:
https://github.com/cosinusoidally/mishmashvm/
and https://github.com/cosinusoidally/tcc_bootstrap_alt/
veltas|22 days ago
This is a great demonstration of how simple the bare bones of C are, which I think is one reason I and many others find it so appealing despite how Spartan it is. C really evolved from B which was a demake of Fortran, if Ken Thompson is to be trusted.
JamesTRexx|22 days ago
And PS, it's "chose your own adventure". :-) I love minimalism.
riedel|22 days ago
Discussed at the time: https://news.ycombinator.com/item?id=36064971
dang|22 days ago
SectorC: A C Compiler in 512 bytes - https://news.ycombinator.com/item?id=36064971 - May 2023 (80 comments)
gjvc|21 days ago
wzbtoolbox|21 days ago
Not saying we should all write boot sector code, but reading through projects like this is genuinely humbling. Great educational resource too.
lock1|21 days ago
On other HN posts, they're stating something like "software development is dead", "LLM as a compiler", "Do you read compiled assembly?", and so on.
While some other posts like this contain huge mechanical sympathy and literally r/w the assembly directly.
mojuba|22 days ago
vidarh|22 days ago
unknown|22 days ago
[deleted]
sanufar|22 days ago
fix4fun|22 days ago
PS. There left 21 bytes (21 * 0x00 - from 0x01e0 to 0x01fd). Maybe something can be packed there ;)
avadodin|21 days ago
benj111|21 days ago
shikaan|21 days ago
Maybe it's time to equip it with a C compiler...
[1]: https://github.com/shikaan/osle
fooker|22 days ago
Fun fact, Tiny C Compiler was derived from such a C compiler submitted to the the International Obfuscated C Code Contest.
https://www.ioccc.org/2001/bellard/index.html
xorvoid|22 days ago
https://xorvoid.com/otcc_deobfuscated.html https://github.com/xorvoid/otcc_deobfuscated
pseudohadamard|22 days ago
DeathArrow|22 days ago
EGreg|22 days ago
https://www.oocities.org/trentgamblin/sizehack/entries.html#...
kreelman|22 days ago
If you're running on Linux, adjust the qemu call to use alsa rather than coreaudio.
I generated a pull request for this on Github. If the author is happy enough with my verbose shell scripting style :-) it might get included.
unknown|21 days ago
[deleted]
userbinator|22 days ago
drob518|21 days ago
zahlman|21 days ago
I could have sworn I remembered atoi() being defined to return 0 for invalid input (i.e. text not representing an integer in base ten).
MobiusHorizons|21 days ago
alittlebee|21 days ago
hgs3|21 days ago
SeanSullivan86|22 days ago
userbinator|22 days ago
[deleted]
NooneAtAll3|22 days ago
was it supposed to be "<150"?
owalt|22 days ago
wbsun|22 days ago
gonzus|22 days ago
benj111|21 days ago
And anyway, isn't that kind of missing the point. 512 bytes isn't much. Your comment is nearly a 5th of that budget.
pilord314|22 days ago
userbinator|22 days ago
[deleted]
kayo_20211030|22 days ago
MORPHOICES|21 days ago
[deleted]