4 ms·
> Instead of translating what you’d like the hardware to perform to C literally, treat C as a higher-level language, because it is one. Alternately, stop writi
by Hizonner 2y ago
> Instead of translating what you’d like the hardware to perform to C literally, treat C as a higher-level language, because it is one.
Alternately, stop writing code in C.
- oguz-ismail 2y agoimpossible no serious alternative
- tialaramex 2y agoFor very small platforms, where it's a struggle to have a C compiler because a "long int" of 32 bits is already a huge challenge to implement, let alone "long long int" - stop using high level languages. Figure out the few dozen machine code instructions you want for your program, write them down, review, translate to binary, done. For the bigger systems where that's not appropriate, you'll value a more expressive language. I recommend Rust particularly, even though Rust isn't available everywhere there's an excellent chance it covers every platform you actually care about.
- oguz-ismail 2y ago[flagged]
- saagarjha 2y agoPeople wrote and continue to write C for 16-bit platforms just fine
- tialaramex 2y ago16-bit is huge. Rust will fit fine on a 16-bit platform. We're not talking about these big modern systems.
- IshKebab 2y agoRust doesn't support 16-bit architectures. It theoretically could but 16-bit architectures are completely obsolete and almost unused, so there's no real need.
- xandrius 2y agoNo true scotsman either.
- IshKebab 2y agoRust and Zig are the serious alternatives for cases where you need a "zero cost" language. If you don't (plenty of C code doesn't) there are endless serious alternatives. I think you could argue that Zig is still very new so you might not want to use it for that reason, but otherwise there is no reason to use C for new projects in 2025.
- oguz-ismail 2y ago> Rust one compiler, two platforms, no spec > Zig dollar store rust
- IshKebab 2y agoOoo now do C!
- ratmeadow 2y agoIMO one of the most disappointing things about C: it smells like it should be a straightforward translation to assembly, but actually completely is not because of the "virtual machine" magic the Standard uses which opens the door to almost anything. Oh you would like a byte? Is that going to be a 7 bit, 8 bit, 12 bit, or 64 bit byte? It's not specified, yay! Have fun trying to write robust code.
- HeliumHydride 2y agoC++ has made efforts to fix some of this. Recently, they enforced that signed integers must be two's complement. There is a proposal currently to fix the size of bytes to 8 bits.
- ratmeadow 2y agoYes, which is excellent (although 50 years too late, I'll try not to be too cynical...). The problem is that C++ is a huge language which is complex and surely not easy to implement. If I want a small, easy language for my next microprocessor project, it probably won't be C++20. It seems like C is a good fit, but really it's not because it's a high level language with a myriad of weird semantics. AFAIK we don't have a simple "portable assembler + a few niceties" language. We either use assembly (too low level), or C (slightly too high level and full of junk).
- bobmcnamara 2y agoAhem, it's specified to not be 7.
- tialaramex 2y agoAbstract. It's an Abstract machine, not a Virtual machine.
- zajio1am 2y agoSize of byte is implementation-defined, not unspecified. Why is that a problem for writing robust code? It is okay to assume implementation-defined behavior as long as you are targeting a subset of systems where these assumptions hold, and if you check them at build-time.
- 1over137 2y agoI'm excited about -fbounds-safety coming soon: https://github.com/llvm/llvm-project/commit/64360899c76c https://github.com/llvm/llvm-project/commit/64360899c76c
- liontwist 2y agoNo. I don’t think I will.
- kerkeslager 2y agoThat's just not an option in a lot of cases, and it's not a good option in other cases. Like it or not, C can run on more systems than anything else, and it's by far the easiest language for doing a lot of low-level things. The ease of, for example, accessing pointers, does make it easier to shoot yourself in the foot, but when you need to do that all the time it's pretty hard to justify the tradeoffs of another language. Before you say "Rust": I've used it extensively, it's a great language, and probably an ideal replacement for C in a lot of cases (such as writing a browser). But it is absolutely unacceptable for the garbage collector work I'm using C for, because I'm doing complex stuff with memory which cannot reasonably be done under the tyranny of the borrow checker. I did spend about six weeks of my life trying to translate my work into Rust and I can see a path to doing it, but you spend so much time bypassing the borrow checker that you're clearly not getting much value from it, and you're getting a massive amount of faffing that makes it very difficult to see what the code is actually doing. I know HN loves to correct people on things they know nothing about, so if you are about to Google "garbage collector in Rust" to show me that it can be done, just stop. I know it can be done, because I did it; I'm saying it's not worth it.
- uecker 2y agoOr catch them using a sanitizer: https://godbolt.org/z/z9WKs5aYv https://godbolt.org/z/z9WKs5aYv