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

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.