423 karma · joined Oct 20, 2022 (4y ago) · 56 submissions
comment 1y ago · link · parent
This is not the whole story. You're making it sound like uninitialized variables _have_ a value but you can't be sure which one. This is not the case. Uninitialized variables don't have a value at all! [1] has a good example that shows how the intuition of "has a value but we don't know which" is wrong:
use std::mem;
fn always_returns_true(x: u8) -> bool {
x < 120 || x == 120 || x > 120
}
fn main() {
let x: u8 = unsafe { mem::MaybeUninit::uninit().assume_init() };
assert!(always_returns_true(x));
}
If you assume an uninitialized variable has a value (but you don't know which) this program should run to completion without issue. But this is not the case. From the compiler's point of view, x doesn't have a value at all and so it may choose to unconditionally return false. This is weird but it's the way things are.It's a Rust example but the same can happen in C/C++. In [2], the compiler turned a sanitization routine in Chromium into a no-op because they had accidentally introduced UB.
comment 1y ago · link · parent
From what I can tell, the only significant difference between C and Odin mentioned in the post is that Odin zero-initializes everything whereas C doesn't. This is a fundamental limitation of C but you can alleviate the pain a bit by writing better primitives for yourself. I.e., you write your own allocators and other fundamental APIs and make them zero-initialize everything.
So one of the big issues with C is really just that the standard library is terrible (or, rather, terribly dated) and that there is no drop-in replacement (like in Odin or Rust where the standard library seems well-designed). I think if someone came along and wrote a new C library that incorporates these design trends for low-level languages, a lot of people would be pretty happy.
[1]: https://www.rfleury.com/p/untangling-lifetimes-the-arena-all...
4.
Ask HN: Future-proof way of archiving web pages?
1 points · by D4ckard · 1y ago · 2 comments
comment 1y ago · link · parent
comment 1y ago · link · parent
There are some niceties about inline completion (like spelling out a log message that's obvious from the surrounding code) but I don't get the hype much beyond that.
Maybe I'm missing some feature though ...
comment 1y ago · link · parent
comment 1y ago · link · parent
comment 1y ago · link · parent
I don't include the null-terminator because I use this type in my own environment where I never use null-terminated strings so there is no need for it.
14.
Writing a BIOS bootloader for 64-bit mode from scratch(thasso.xyz ↗)
260 points · by thasso · 2y ago · 80 comments
comment 2y ago · link · parent
Location: Northern Germany
Remote: Possibly; I'd prefer to work in person
Willing to relocate: Yes
Technologies: C, Rust, (some) Haskell, UNIX Shell
Résumé/CV: https://drive.proton.me/urls/4AEW15FMVM#amFzaHXAgqb6
Email: thassilo.schulze (at) proton.me
I'm an aspiring developer, into programming languages and DevTools. Last year, I built a C debugger from scratch, and recently I've been programming in Haskell a lot. I will graduate from German high school this spring, and I'm looking for internship opportunities.comment 2y ago · link · parent
comment 3y ago · link · parent
The idea of only watching saddens me. Doing any creative work is incredibly satisfying, and I think has positive effects on long-term happiness and self-worth.
comment 3y ago · link · parent
Haha, the emoji thing was something I was doing for about a week or so. You see emojis used a lot more around Rust I guess. I never bothered to remove them. I think the bugs around the PID are fun. The ones in the comments might go at some point, though I didn't experience any problems with editors (Helix, Emacs, and VSCode all work) so far.
Should I maybe disabled printing emojis to standard output in the REPL if terminal colors are disabled as well?