3 ms·
I think the point is that it's funny that the standard library has to use unsafe to implement a data structure that's like the second data structure you learn i
by vikramkr 2y ago
I think the point is that it's funny that the standard library has to use unsafe to implement a data structure that's like the second data structure you learn in an intro to CS class
- Sharlin 2y agoYeah, but Rust just proves the point here that (doubly) linked lists a) are surprisingly nontrivial to get right, b) have almost no practical uses, and c) are only taught because they're conceptually nice and demonstrate pointers and O(1) vs O(n) tradeoffs. Note that safe Rust has no problems with singly-linked lists or in general any directed tree structure.
- School-Cotton 2y agoWhy is it particularly funny? C has to make a syscall to the kernel which ultimately results in a BIOS interrupt to implement printf, which you need for the hello world program on page 1 of K&R. Does that mean that C has no abstraction advantage over directly coding interrupts with asm? Of course not.
- cesarb 2y ago> C has to make a syscall to the kernel which ultimately results in a BIOS interrupt to implement printf, That's not the case since the late 1990s. Other than during early boot, nobody calls into the BIOS to output text, and even then "BIOS interrupt" is not something normally used anymore (EFI uses direct function calls through a function table instead of going through software interrupts). What really happens in the kernel nowadays is direct memory access and direct manipulation of I/O ports and memory mapped registers. That is, all modern operating systems directly manipulate the hardware for text and graphics output, instead of going through the BIOS.
- School-Cotton 2y agoThanks for the information (I mean that genuinely, not sarcastically — I do really find it interesting). But it doesn’t really impact my point.
- tux3 2y agoNo, that's how the feature is supposed to work. You design an abstraction which is unsafe inside, and exposes a safe API to users. That is really how unsafe it meant to be used. Of course the standard library uses unsafe. This is where you want unsafe to be, not in random user code. That's what it was made for.