r/programming • • May 01 '18

C Is Not a Low-level Language - ACM Queue

https://queue.acm.org/detail.cfm?id=3212479
152 Upvotes

303 comments sorted by

View all comments

Show parent comments

76

u/imperialismus May 01 '18

But most people look at this relatively.

That is indeed what the author starts out by saying: imagine a spectrum where assembly is on one end and the most advanced computer interface imaginable is on the other. Then he goes on to talk about out of order execution and cache and how they don't map to C even though assembly has no concept of OoO or cache either.

101

u/yiliu May 01 '18

So really what he's saying is that C is a low-level language...for a different (and much simpler) system than what your code is actually running on. What you're actually running on is kind of a PDP-11 hardware emulation layer on top of a heavily-parallelized multi-core architecture with complex memory and cache layouts. Maintaining that hardware emulation layer is becoming a burden, and is starting to result in exploits and regressions.

10

u/munificent May 03 '18

Maintaining that hardware emulation layer is becoming a burden

I think a better way to describe it is that it's an increasingly leaky abstraction. And those leaks are becoming so bad that we should consider whether it's even the right abstraction to use anymore.

9

u/Valmar33 May 02 '18

Would make a good tl;dr. :)

3

u/[deleted] May 03 '18

So really what he's saying is that C is a low-level language...for a different (and much simpler) system than what your code is actually running on.

Something like Itanium actually. I'm not sure if those features are actually exposed in any architecture anyone actually uses.

23

u/lelanthran May 01 '18

Then he goes on to talk about out of order execution and cache and how they don't map to C even though assembly has no concept of OoO or cache either

I've made the same observation down below, where I was having fun with some trolls (hence got downmodded).

This article is a more a "Programming Language Problems" than a "C Language Problems" article. I'm not sure what the author's intention was to deride C for having all these problems when literally every other language, including assembly, has these problems because these are processor problems.


How is that a C problem as opposed to a programming language problem?

Look, I get the point that the author is trying to make WRT to spectre-type attacks, but the how is this a C problem and not a Programming Language problem?

It doesn't matter what programming language you use, you are still open to spectre. It doesn't even matter if you go off and design your own language that emits native instructions, you're still going to get hit by errors in the microcode that lies beneath the published ISA.

The only way to avoid this is to emit microcode and bypass the entire ISA entirely, at which point you can use any high level language (C included) that has a compiler that emits microcode.

Chances are, even if you did all of the above, you'd find there's no way to actually get your microcode to run anyway.

So, given the above, why does the article have such a provocative title, and why is the article itself written as if this is a C problem? It clearly isn't.

18

u/yiliu May 01 '18

I'm not sure what the author's intention was to deride C for having all these problems

He's challenging the assumption that people have that C is "close to the metal". That's definitely something people believe about C, as opposed to other programming languages, but he points out that it's no longer particularly true.

At the end of the article, the author takes a shot at suggesting some alternative approaches (Erlang-style actor model code, immutable objects, etc.

6

u/Valmar33 May 02 '18 edited May 02 '18

Erlang-style actor model code

Ever since learning about the actor concurrency model in this Hacker News article, multi-threading started to sound ridiculously easy.

6

u/d4rkwing May 02 '18

How about C is “close to the OS”.

6

u/lelanthran May 02 '18

If C is no longer close to the metal, then nothing is, including assembler on x86.

29

u/yiliu May 02 '18

Right, exactly. That's his point. People think other languages are high-level, but C is close to the metal. But the metal C was close to is long gone, and there's now many layers of abstraction between you and the hardware--and those layers are starting to leak.

He didn't claim other languages are lower-level, and this wasn't a hit-piece on C. It's just an interesting realization. I'm detecting a fair bit of wounded pride in this thread.

9

u/AlmennDulnefni May 02 '18

C is as close to the metal as it ever was. The metal just got a lot weirder. And maybe a bit crumbly.

9

u/cbbuntz May 02 '18

If you think about a basic for loop using pointers

for (int *p = start; p < end; p++)

You know pretty much know exactly how that would look on an older CPU with no vectorization and a more limited instruction set. But there's a lot more going on under the hood now, so you can make an educated guess as to what the generated code will be, but it's a lot more abstract now. You'd have to heavily rely on intrinsics to get predictable results now. C wasn't written for modern CPUs, so compilers have to automagically translate it to something that makes more sense for modern architectures. They usually do a good job, but Dennis Ritchie wouldn't make the same language if were to write it from the ground up today.

7

u/pjmlp May 02 '18

Exactly, those nice x86 Assembly opcodes get translated into microcode that is actually the real machine code.

9

u/AntiauthoritarianNow May 02 '18

I don't understand why you think this is "deriding C". Saying that something is not low-level is not saying that it is bad.

9

u/[deleted] May 02 '18

Because this paranoid moron apparently believes that the last holding bastions of C programming are besieged by hordes of infidel Rust and Go barbarians. Therefore anything that is not praising C must be a plot of the said barbarians, obviously. Just look at his posting history.

13

u/munificent May 03 '18

this paranoid moron

Unless your goal is to devolve reddit to a shouting match between children, language like this is not helpful.

0

u/[deleted] May 03 '18

Some people here are beyond any hope anyway, so it's better to point it out (and, ideally, exclude them from discussion) right from the very beginning. In this case it's pretty obvious.

5

u/immibis May 06 '18

Unless your goal is to devolve reddit to a shouting match between children, language like this is not helpful.

0

u/bumblebritches57 May 04 '18

Hop on over to webdev if that's how you feel, soyboy.

4

u/immibis May 06 '18

Unless your goal is to devolve reddit to a shouting match between children, language like this is not helpful.

→ More replies (2)

4

u/PaulBone May 03 '18

Because these problems in the CPU are created when CPU designers cater to C (and C-like) languages.

4

u/lelanthran May 03 '18

Because these problems in the CPU are created when CPU designers cater to C (and C-like) languages.

Nonsense. The CPU designers aren't trying to cater to C, they're just being backwards compatible.

Look at Itanium to see what happens when you aren't backwards compatible.

→ More replies (13)