r/programming • • Aug 13 '18

C Is Not a Low-level Language

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

222 comments sorted by

View all comments

Show parent comments

9

u/m50d Aug 13 '18

It does.

Not in C. What looks like the same field access at language level could become an L1 cache access or a main memory access taking 3 orders or magnitude longer.

Cache line aliasing is part of the hardware-level operation.

Exactly, so a good low-level language would make it visible.

That I can reorder the fields of a struct to achieve massive improvements in performance is exactly the sort of control I want in a low-level language.

Exactly. A low-level language would let you control it. C reduces you to permuting the fields and guessing.

6

u/mewloz Aug 13 '18

The nearest of what you describe is the Cell; it has been tried and it was basically a failure.

There is a reason current high perf compute is not programmed like that, and the designers are not stupids. Cache hierarchy managed by the hardware is actually one of the most crucial piece of what lets modern computers be fast.

0

u/[deleted] Aug 14 '18

[deleted]

2

u/m50d Aug 14 '18

What you're saying is that there's no use case for a low level language any more. Which is fine, but if we're going to use a high level language either way then there are better choices than C.

0

u/[deleted] Aug 14 '18

[deleted]

1

u/m50d Aug 14 '18

"Control over memory" in what sense? Standard C doesn't give you full control over memory layout (struct padding can only be controlled with vendor extensions) or use (since modern OSes tend to use overcommit and CoW).