News for hackers. Stuff that matters.
Re:Next steps for Rust in the kernel by dijit on Wednesday September 21, 2022 @09:11AM (#32924662)
Steve Klabnik has done a lot for systems programming and that post is a lot more even-handed than you're suggesting.

If, however, we're talking about the kernel then perhaps we should listen to what Torvalds says about this topic.

"People who designed C, designed it at a time where the language had to be geared towards the output, so when I read C I can think about the Assembly that it will create":

http://www.youtube.com/watch?v=MShbP3OpASA&t=20m45s

Consider that he said this in a time with C++, even if Rust was in its infancy: it is not as tied to the assembly it produces. Not by a long shot.

Re:Next steps for Rust in the kernel by TrickardRixx on Wednesday September 21, 2022 @09:19AM (#32924761)
Sounds to me like if I want to know "how computers think" I should learn assembly.
Re:Next steps for Rust in the kernel by dijit on Wednesday September 21, 2022 @09:26AM (#32924832)
I know you're trying to be a smart-arse; but by virtue of using C you will learn Assembly.

The issue with Assembly directly is that it's absurdly non-portable, too low level and too unstructured to do anything reasonable with it.

There's a reason that Linux is written in C and not ASM Directly.

Re:Next steps for Rust in the kernel by jcranmer on Wednesday September 21, 2022 @10:22AM (#32925545)
> by virtue of using C you will learn Assembly.

Even interpreting this as charitably as possible--that you don't mean literally learning assembly but rather learning everything besides specific assembly syntax that you would have picked up from learning assembly--this claim doesn't hold water.

For starters, C isn't that much closer to hardware than, say, Java. The main differences you have with C are that a) C has a pointers-are-almost-integers model [1] and b) C has a more limited runtime than other languages. C is still a fundamentally based on an abstract machine semantics model, and that abstract machine doesn't have a close bearing on modern hardware.

In particular, C does not distinguish between registers and memory, and if I had to pick the single most salient feature of modern hardware you need to understand well to be able to say you understand how computers work, it's the register/memory distinction. If you think processors are mostly like they were in the 1970s--when you could say "add 1 to this memory location"--then C's shrugging off the register/memory distinction makes sense, but this is a situation that hasn't been true for several decades.

Another failure of C is that it's far less expressive than assembly. There are features in other languages that are impossible to express in C. How do you write a function with multiple entry points, as you can in Fortran? Or a coroutine, as you can in Algol? Or nested functions, as in Pascal? Or try-catch, as in C++? Or functions with multiple return values, as in Matlab? Indeed, how do you write something like JMP *reg in C, a useful primitive for state machines?

No, C does not come close to being a good description of modern processors, where "modern" means "anything that came out since I was born."

[1] Not going to open up the can of worms that is pointer provenance.

Re:Next steps for Rust in the kernel by cesarb on Wednesday September 21, 2022 @10:41AM (#32925852)
> C does not distinguish between registers and memory

Just nitpicking, but doesn't C have the register keyword? (I know it does nothing at all nowadays, but AFAIK it did make a slight difference back in the dark ages.)

Re:Next steps for Rust in the kernel by tialaramex on Wednesday September 21, 2022 @12:57PM (#32927958)
C's register keyword is a storage specifier, it actually does do something, what it does is announce "This might not have an address" (your CPU registers don't have addresses) and so you can't make a pointer to it with the unary & address operator.

Your C compiler might conclude - even if it doesn't decide to put the variable in a register - that since the variable notionally doesn't have an address some optimisations are available which it can't otherwise be sure are safe.

Re:Next steps for Rust in the kernel by jcranmer on Wednesday September 21, 2022 @10:50AM (#32925988)
Considering that `volatile register _Atomic int x;` is a totally legal statement, and two [1] of those keywords have semantics that are only relevant for memory operations, I'd say that the "register" keyword isn't sufficient to distinguish register from memory.

[1] Okay, the official semantics of "volatile" strictly speaking are completely orthogonal to memory, but the practical effect that everyone agrees on (don't optimize this memory access) is inherently oriented towards memory, and the fact that the semantics are so vague about what it actually does is partially a reflection of the fact the semantics themselves don't distinguish between register and memory.

Re:Next steps for Rust in the kernel by UncleMeat on Wednesday September 21, 2022 @09:46AM (#32925086)
> by virtue of using C you will learn Assembly.

I don't believe this at all. You won't learn how to deal with limited numbers of registers. You won't learn about method prologues and epilogues. You won't learn about oodles of stuff.

Re:Next steps for Rust in the kernel by Jensson on Wednesday September 21, 2022 @10:02AM (#32925301)
> You won't learn how to deal with limited numbers of registers. You won't learn about method prologues and epilogues.

Those things takes like an hour to learn, translating C to assembly is trivial, it takes time and will be verbose but it isn't hard at all. So even though you don't learn all the details you still learn all the higher level stuff related to assembly programming when you program in C.

This isn't true for other languages, translating arbitrary C++ or Java or Javascript to assembly is really hard, so they don't teach you to think like an assembly programmer.

Re:Next steps for Rust in the kernel by dijit on Wednesday September 21, 2022 @10:05AM (#32925337)
> deal with limited numbers of registers

I mean; you will likely end up stepping through debuggers where you will see registers being used. At least if you learned C like I learned C.

Similarly for Prologue and Epilogue.

"why does a function call have a cost" is a common question and it's solved forever after an hour googling.