Live data from Hacker News

C Is Not a Low-Level Language

queue.acm.org

121–130 of 326 posts

Re: C Is Not a Low-Level Language

#121
post #60

Earlier quoted context omitted.

On the flipside, doesn't it allow more or less direct memory access?

I mean, yes, no, it depends on what you mean? You can write to null in C, your operating system rejects it. You can write past your allocated memory, your OS rejects it. It's not like just because it's written in C it gets to read the kernel memory - it's just that you can try. All memory access in userspace is mediated by the MMU, so nothing in C gets "direct" memory access - but it does allow you to screw up your o…

In writing h kernal modules in C for vxworks, I find people quite often write/read data from hard-coded memmory addresses.

Re: C Is Not a Low-Level Language

#122

I really really liked this article, and reading the comments here is blowing my mind. Did we read the same thing? I think it's a strong insight that insight that chip designers and compiler vendors have spent person-millenia maintaining the illusion that we are targeting a PDP-11-like platform even while the platform has grown less and less like that. And, it turns out, with things like Spectre and the performance co…

Actually, the author's argument about PDP-11 is interesting because C would have never been considered a low level language back then, for any platform.

Wiki definition, also what I was taught in my first CS class:

"A low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture—commands or functions in the language map closely to processor instructions. Generally this refers to either machine code or assembly language."

The term is evolving to match the time, as shown by the author's interpretation already being higher level than the original intention despite the goal of preventing exactly that.

Re: C Is Not a Low-Level Language

#123
post #104

Earlier quoted context omitted.

It isn't at all similar. JVM bytecode is a pretty high-level IR for tokenized Java. The JVM's main unit of optimization is a method, not instructions. Its key component is a compiler, it's even called that. An x86 cpu, as the article points out, spends inordinate resources looking for ILP. It's not a compiler in any reasonable sense of the word, while a JVM is.

`javac` is a compiler. The JVM is an execution platform, just like modern x86.

What's the word that comes after 'JIT'?

Re: C Is Not a Low-Level Language

#124

Earlier quoted context omitted.

> Which is still an interesting and useful fact. I think it just leads to quibbling over the boundary of low level, as is happening here. I think it's just important to know that the definition changes over time relative to the state of the art. C was once considered high level. In the future, if programming languages evolve to a more natural language state, then sending serial instructions to the computer in a stran…

Quibbling and language-lawyering aside, this is clearing up a real, fundamental misunderstanding that a lot of people have. Anecdotally I have encountered loads of programmers who actually believe that there is a straightforward correspondence between C code and what the machine is actually doing, which is wrong. So regardless of how you want to define "low-level", understanding this point is useful.

> actually believe that there is a straightforward correspondence between C code and what the machine is actually doing, which is wrong.

That really depends on your definition of "the machine". If "the machine" is "hardware", then sure. But if software is a considered piece of logic onto itself, that, when pitted against a sound model of an architecture will result in a series of logical steps, it's different: there is a very straightforward correspondence between the model-machine and assembly/C. Whether there is a 1-1 correspondence between the model-machine and any accidental hardware it is implemented is not that relevant.

So if low-level is defined as the lowest level that any hardware abstraction functions exactly as its logical function and not its silicon, it tells you exactly what the machine should be doing, even if it's doing it through different means.

Re: C Is Not a Low-Level Language

#126

Earlier quoted context omitted.

> If C is not a low level language then a low level language does not exist for modern CPUs I think that's a fair conclusion though, I don't think the article is misleading. x86 assembly is a high level language. It's analogous to JVM bytecode. Modern x86 processors are more like a virtual machine for x86 bytecode.

It's a fair conclusion if you're willing to accept that the phrase "low-level language" has approximately zero modern examples. Or maybe we should relax the definition of "low-level language" a bit?

I think the author of the article is willing to accept that, and it's part of his point. The point is not to label languages, but to illuminate how we ended up with our current combination of software and hardware design. He points out that we are in a local-maximum with respect to processor performance because most of the optimizations we've made in processor design the past few decades break the C abstract machine. That requires the compiler and processor to go through awkward contortions to present the fiction of that abstract machine while still getting good performance. The final section, "Imagining a Non-C Processor", is where he explores this idea.

Re: C Is Not a Low-Level Language

#127

Earlier quoted context omitted.

> Which is still an interesting and useful fact. I think it just leads to quibbling over the boundary of low level, as is happening here. I think it's just important to know that the definition changes over time relative to the state of the art. C was once considered high level. In the future, if programming languages evolve to a more natural language state, then sending serial instructions to the computer in a stran…

Quibbling and language-lawyering aside, this is clearing up a real, fundamental misunderstanding that a lot of people have. Anecdotally I have encountered loads of programmers who actually believe that there is a straightforward correspondence between C code and what the machine is actually doing, which is wrong. So regardless of how you want to define "low-level", understanding this point is useful.

If you think of the hardware as a black box, it does correspond to the instruction set architecture presented. Generally you don't think about implementation details of an op-amp when you wire it into a circuit. The issue is that CPUs have become so complex that the lines are blurred, since the external interface is so removed from what's going on inside with micro code and ooe and cache. So while pedantically there are no longer low level language outside of microcode, that renders the term useless, and I'd prefer the natural language evolution that's occurring.

Re: C Is Not a Low-Level Language

#128

I really really liked this article, and reading the comments here is blowing my mind. Did we read the same thing? I think it's a strong insight that insight that chip designers and compiler vendors have spent person-millenia maintaining the illusion that we are targeting a PDP-11-like platform even while the platform has grown less and less like that. And, it turns out, with things like Spectre and the performance co…

> cost of cache misses How is the C memory model a leaky abstraction here? What better way do you suggest? Are we not fine coding sequential (in memory) datastructures in C?

C leads you to believe that memory access has uniform cost regardless of address. What is the perf cost of:

    *foo
Depending on what foo points to, and which memory you have previously read, the cost can vary by close to two orders of magnitude on many chips.

C does give you the ability to control those costs, but controlling how you lay out your data in memory and controlling imperatively in which order you access it. But the language doesn't show you those costs in any way.

Re: C Is Not a Low-Level Language

#129

This article makes some valid points but is overall rather misleading I think. Almost all of the reasons given why C is "not a low-level language" also apply to x86/x64 assembly. Register renaming, cache hierarchies, out of order and speculative execution etc are not visible at the assembly / machine code level either on Intel or other mainstream CPU architectures like ARM or Power PC. If C is not a low level languag…

> If C is not a low level language then a low level language does not exist for modern CPUs I think that's a fair conclusion though, I don't think the article is misleading. x86 assembly is a high level language. It's analogous to JVM bytecode. Modern x86 processors are more like a virtual machine for x86 bytecode.

>x86 assembly is a high level language. It's analogous to JVM bytecode.

If you take this position, then having the distinction between "low level" and "high level" languages becomes pointless, and we have no way to distinguish between languages like x86 assembly and C and languages like Python and Haskell. This is why we use the terms "low level" and "high level": some of these languages have a lower level of abstraction than others. The fact that it's not giving you a great idea of exactly what's happening in the transistors is irrelevant: "low" and "high" are relative terms, not absolute.

Re: C Is Not a Low-Level Language

#130

I really really liked this article, and reading the comments here is blowing my mind. Did we read the same thing? I think it's a strong insight that insight that chip designers and compiler vendors have spent person-millenia maintaining the illusion that we are targeting a PDP-11-like platform even while the platform has grown less and less like that. And, it turns out, with things like Spectre and the performance co…

Actually, the author's argument about PDP-11 is interesting because C would have never been considered a low level language back then, for any platform. Wiki definition, also what I was taught in my first CS class: "A low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture—commands or functions in the language map closely to proces…

> Actually, the author's argument about PDP-11 is interesting because C would have never been considered a low level language back then, for any platform.

Sure, agreed, but I don't think it's super interesting that words evolve in meaning over time.

What I find strange about the comments here is that some people think the article's title is bad even though my experience is that many people today do think "C is a low level language" is a reasonable thing to say.

Post reply on HN