Re:Beej's Guide to C Programming
by tialaramex on Sunday February 26, 2023 @09:20PM
(#34952188)
Well, let's just try ripping all mention of Rust out:
""While obviously C is closer to the metal than say, Python, I am increasingly dubious about the value of any of these high level languages (yes, even C) to learn "How the machine really works". I reckon it's probably more instructive to write a little bit of ARM assembly than to learn enough C to get to the same place today.""
Now, why am I talking about "How the machine really works". Well, here's the next line from Beej:
> When you learn C, you learn about how software interfaces with computer memory at a low level
You don't. You're learning about how C software interfaces with the memory of C's abstract machine, but that's not how your machine's memory works, not even close. For example C just magically ensures the alignment is correct all the time, but the actual memory relies on programmers to ensure they only perform aligned access, unaligned access may blow up your whole program or make it enormously slower, which is worse ?
On the other hand C's Pointers are not just addresses. Even though C makes them look more like they are than many languages with a pointer type, they still aren't just addresses. If you mistake them for addresses, you'll get punished by your compiler, although just exactly when is hard to predict - this is a game of Russian Roulette. However the actual memory in your computer really does just have addresses and they're just numbers like any other numbers.
""While obviously C is closer to the metal than say, Python, I am increasingly dubious about the value of any of these high level languages (yes, even C) to learn "How the machine really works". I reckon it's probably more instructive to write a little bit of ARM assembly than to learn enough C to get to the same place today.""
Now, why am I talking about "How the machine really works". Well, here's the next line from Beej:
> When you learn C, you learn about how software interfaces with computer memory at a low level
You don't. You're learning about how C software interfaces with the memory of C's abstract machine, but that's not how your machine's memory works, not even close. For example C just magically ensures the alignment is correct all the time, but the actual memory relies on programmers to ensure they only perform aligned access, unaligned access may blow up your whole program or make it enormously slower, which is worse ?
On the other hand C's Pointers are not just addresses. Even though C makes them look more like they are than many languages with a pointer type, they still aren't just addresses. If you mistake them for addresses, you'll get punished by your compiler, although just exactly when is hard to predict - this is a game of Russian Roulette. However the actual memory in your computer really does just have addresses and they're just numbers like any other numbers.