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

11

u/jerf May 01 '18 edited May 01 '18

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.

10

u/oridb May 01 '18 edited May 01 '18

I completely disagree. For one thing, I cite the article's own listing of the differences, and the fact they are visible and relevant.

Once again, if that is the case, the argument can be made that assembly is not a low level language, because these differences that the article discusses are also not reflected in assembly language. There's an argument to be made there, I suppose, but that would also imply that there is no low level language that a programmer who does not work at a CPU manufacturer can use.

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?

It runs on the GPU in the same sense that it runs on the CPU. In many ways, it targets the GPU better than the CPU, because GPUs are exposed as scalar architectures, where vector instructions are not exposed by the ISA. Vector instructions are the biggest mismatch between C and current hardware.

3

u/AntiauthoritarianNow May 01 '18 edited May 01 '18

Regarding your first point, this topic is starting to make me come around to the idea that assembly is no longer a low level language, at least for CPUs that perform their own optimizations. It's certainly not high-level, but it's more of an intermediary representation.

4

u/[deleted] May 01 '18

Well, CUDA is a subset of C++, and OpenCL is an extension of a subset of C99. And this is exactly what's wrong with them.