I would have to disagree. C is a low-level language, for a computer that isn't the one you're programming on, so you're really working with a simulation of that computer rather than the hardware you're really on. That doesn't make C a mid-level language... it makes it a mismatched language. For instance, C just has no concept of your GPU, which on many computers is in some sense the majority of raw computational power available from the hardware! And C just has nothing for that. It's never heard of GPUs.
(Neither do most other languages. I submit that part of that is the way that C has controlled our very conception of what a programming language is for so long that people creating new languages tend to create languages that are often "C, but with this new feature", rather than "Let's think about how to create a language that takes advantage of the CPU and the GPU together." Or "let's build a language that works with cloud abstractions and has a fundamental concept of 'a function that may not return' or something". Or any number of other interesting avenues left unexamined because A Computer Language Is Basically C With More Features.)
C is a low-level language, for a computer that isn't the one you're programming on, so you're really working with a simulation of that computer rather than the hardware you're really on.
Not every high-level language claims to be an accurate representation of the hardware the way C proponents claim it to be. In fact, pretty much nothing else does. So there's no contradiction there.
I'm a C proponent, and I'm saying that the C abstract machine isn't a 1 to 1 mapping to any hardware that exists. So what you're saying is empirically not true.
That's a motte & bailey argument. C has been promoted for decades as "the language that's close to the bare metal", as "high-level assembler", and everyone knows it.
And it's not like it was a lie. It was those things. It's just that step by step, year by year, CPU by CPU, it gradually ceased to be. And so there's no sharp line where it ceased to be true. I can't say "Oh, it was the Pentium that did it in, yeah." But it went from true, to an approximation of true, to a useful lie to tell students (which I consider not necessarily a bad thing), to where we are today, where it is an active impediment to both understanding modern CPUs and programming them well.
I mean, it's still one of the closest languages to assembly.
Assembly doesn't get you all that closer to how these machines work as compared to C. That's not saying that C gets you near there, but more that these machines don't expose any public interface that isn't abstracted to a sequential instruction machine that's a close analog of C, including assembly.
Why wouldn't assembly bring you any closer (assuming were just talking about x86-64). While its true that assembly does not provide a 1-1 conversion to machine code, I don't see how it could illustrate a stack based architecture any better.
I mean, these machines are stack machines. There's more gates in the stack engines than the ALUs. And if you treat RSP (and to a lesser degree RBP) as anything other than a stack pointer with stack-like accesses you'll kill performance as you'll fall off into microcode manually synchronizing between the ALUs and the stack engine.
You can see this in AArch64 too where they demoted SP from being a full architectural register vs AArch32 so they don't even have to attempt to synchronize the disjoint hardware.
C is a low-level language, for a computer that isn't the one you're programming on
This is a meme. This meme is false. The pdp11 is close enough to most modern architectures that it would not have affected the design of C too much.
There are differences, but these differences aren't exposed by the assembly language either.
For instance, C just has no concept of your GPU, which on many computers is in some sense the majority of raw computational power available from the hardware!
And yet, it runs just fine on the GPU, once you give the appropriate compiler a hint to compile the function for the GPU.
This is a meme. This meme is false. The pdp11 is close enough to most modern architectures that it would not have affected the design of C too much.
To be fair, modern architectures were designed to run C well. That was the whole point of RISC, take a look at what a compiler actually emits and make a core that runs just that.
This is a meme. This meme is false. The pdp11 is close enough to most modern architectures that it would not have affected the design of C too much.
I completely disagree. For one thing, I cite the article's own listing of the differences, and the fact they are visible and relevant. Considering among those things are "multicore", we're talking some pretty fundamental differences. (C11 sort of has it, but it is clearly bolted on literally decades after the fact, not something C has any concept of.) The article isn't even complete, and this is including as monocasa points out that modern hardware is designed to be a C machine, which means that the differences aren't just "things that happened", but changes that were made despite the fact it would take the hardware farther from what C supports.
Among the other things that C doesn't account for is the importance of the memory hierarchy. It may superficially seem like C has good support for cache locality by letting you arrange structs and pack things tightly, but that's just because things like dynamic scripting languages have such poor cache locality that even C looks good. A language that was truly good with cache locality would be something like that language Jonathon Blow was prototyping that would let you use columnar arrays of data, where arrays slice horizontally on structs instead of just plopping structs down in a row, with a simple specification on the array rather than the manual implementation you'd have to do in C.
(This is another one of those things where C limits the very thoughts of language designers. This is an obvious consequence of the way modern caches work, but few languages have fiddled with this, even though it isn't even that hard, once you're writing your own language.)
And yet, it runs just fine on the GPU, once you give the appropriate compiler a hint to compile the function for the GPU.
Does it run on the GPU, or does it run on a simulation of the C standard machine running on the GPU, resulting in access to only a fraction of the GPU's capabilities?
Honest question. Last I knew you needed CUDA or something to get anything like real access to the GPU's capabilities. Since the entire point here is precisely that merely running C doesn't mean you're getting a good abstraction of your computer's capabilities, a GPU merely running C could very well be merely a more obvious version of the point I'm making about the CPU as well.
For any system architecture in history, the only low level language has been, and is, assembly language. Assembly language is merely the one-to-one direct association to machine language for any CPU. If you want to call C a "mixed" level language, fine. That is merely semantics. But C is not a low level language - only assembly is.
Ehh.. these days even assembly wouldn't constitute a low level language. The machine code that's generated still doesn't run precisely as described. Modern CPUs perform so many optimisations at runtime in terms of instruction re-ordering, register remapping, skipping no-op instructions that even assembly doesn't fit as an accurate description of what the hardware will do.
The thing is, as a programmer you have no control over how those CPU tasks are done - except, of course, if there is a bug that leads to Spectre and others. So, what does it matter if assembler does not account for such tasks?
That's like saying that you're not a true expert car driver because you can't access the steering hydraulic pump with your bare hands to control it.
But I think that's precisely the point of the article - modern "fast" processors are so complex that even plain old assembly isn't low level in the truest sense. So a question is - could we do with simpler (dumber) processors, and assembly that is closer to how processors work today (multithreading, vectorisation, cache), but is not supportive of C?
Well the reason why we've reached this point is because it irritatingly went down the rabbit hole of saying "Well X isn't low level because Y"
Truth is the answer is no, C as a language is close enough to the code ran on the hardware and does not try to abstract away a large amount it does qualify as low level.
Which is ultimately the point of the article tbh. Things have been written in C for decades, so processors expose an interface similar to the kind that C compilers have historically targeted despite operating completely differently under the hood these days.
Maybe that point would have been better made if the author had titled it as "Assembly Is Not a Low-Level Language".
This makes the term "low level languages" useless. We already have a perfectly satisfactory term to refer to assembly languages. Namely, assembly languages.
12
u/jerf May 01 '18
I would have to disagree. C is a low-level language, for a computer that isn't the one you're programming on, so you're really working with a simulation of that computer rather than the hardware you're really on. That doesn't make C a mid-level language... it makes it a mismatched language. For instance, C just has no concept of your GPU, which on many computers is in some sense the majority of raw computational power available from the hardware! And C just has nothing for that. It's never heard of GPUs.
(Neither do most other languages. I submit that part of that is the way that C has controlled our very conception of what a programming language is for so long that people creating new languages tend to create languages that are often "C, but with this new feature", rather than "Let's think about how to create a language that takes advantage of the CPU and the GPU together." Or "let's build a language that works with cloud abstractions and has a fundamental concept of 'a function that may not return' or something". Or any number of other interesting avenues left unexamined because A Computer Language Is Basically C With More Features.)