Hacker News new | past | comments | ask | show | jobs | submit login
What is the simplest self-compiling subset of C?
4 points by sandinmyjoints on March 9, 2021 | hide | past | favorite | 2 comments
See https://github.com/certik/bcompiler/issues/1#issuecomment-793896926



Great question. Here are some candidates:

* https://github.com/rswier/c4

* https://github.com/Fedjmike/mini-c

* https://github.com/rui314/8cc

* https://github.com/rui314/chibicc

* https://github.com/aligrudi/neatcc

Some of them are actually interpreters, and I personally would be interested in actual compilers that generate machine code.


I think there are two aspects to "simplest" here:

1. You want a compiler that's short and easy to understand.

2. You want a simple definition of what this subset of C is so someone using it knows what's allowed and what isn't even if the compiler doesn't give helpful error messages and perhaps doesn't even detect all errors.

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:

* Are you happy with a 32/64-bit char and sizeof(everything) == 1?

* 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's a nasty mismatch with the prototype of main and standard library functions using int.

* If you do throw away the signed/unsigned distinction, do you tell people to survive without <, <=, >, >=, or do you tell them to only compare signed (or only compare unsigned) values?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: