Live data from Hacker News

C Is Not a Low-Level Language

queue.acm.org

41–50 of 326 posts

Re: C Is Not a Low-Level Language

#41
post #26

TLDR: C was close-to-the-metal on the PDP-11 but since then hardware has become more complex while exposing the same abstraction to the C programmer. That means that hardware features such as speculative execution and L1/L2 caching are invisible to the programmer. This was the cause of Spectre and Meltdown and it forces a lot of complexity into the compiler. GPUs achieve high performance in part because their program…

I was with you until the last sentence: "Processors would be able to evolve if they weren't hamstrung by having to support C." I don't think its fair or correct to say that C is the real issue. Recently there have been languages like erlang and support for more functional models that make concurrent code a lot easier to write. The first real consumer multicore processors were only released a bit over 10 years with In…

> Recently there have been languages like erlang

Erlang is decades old. It's 32, only 16 years younger than C.

Re: C Is Not a Low-Level Language

#42
To me the argument's akin to suggesting that Robert Wadlow wasn't tall, because giraffes are taller than Robert Wadlow.

When the spectrum of the context is unambiguous, that's not an argument for finding a way to make it ambiguous.

Re: C Is Not a Low-Level Language

#43
post #35
post #12

Earlier quoted context omitted.

C-like code that runs on GPUs is not even close to normal C, even though the syntax is similar. The way you layout your memory, schedule your threads, and add memory barriers is completely different. You are never going to take a piece of large C code written for a CPU and just run it directly on a GPU.

Huh, that’s weird, I run a C++ compiler directly on my GPU code. The only difference between CPU and GPU code at the function level is whether I tag it with a __global__ macro or not, and lots of functions compile and run for both CPU and GPU. Memory layout, thread scheduling, and barriers are not features of the C language and have nothing to do with whether your C is “normal”. Those are part of the programming mode…

OK, I guess it comes down to what you call "normal" C. I was defining it as what would run on x86 Windows or Linux.

Re: C Is Not a Low-Level Language

#44

Earlier quoted context omitted.

I don’t understand. CPUs do not support C, they support a specific instruction set. What stops them from having instructions for cache management, pipelining, speculative execution hints, etc?

They do not support C officially, but every CPU designer knows that 99%+ of the code that matters is written in C. Therefore they design chips targeting this translation from C. What the authors want is a better lower level interface that would allow for modern processor features without the legacy of the features available to the PDP11.

> 99%+ of the code that matters is written in C

I think a better way of stating this is "99% of the code that matters is written in C, or in a language designed with a similar target architecture as C in mind". Certainly a lot of code that matters is written in C++, Objective-C, and Java, but the same points hold true for all of those.

Re: C Is Not a Low-Level Language

#45

It's all relative. Lower level than what? Higher level than what? C is lower level than a huge number of other languages so I would feel comfortable calling it 'low level'.

Relative to dozens of years of "portable assembly" and "C makes you understand how a computer works" and "C is efficient because it maps to almost 1:1 with CPU operations" and a jillion of related claims.

Depending on your hardware that is still the case. There are plenty of embedded systems where these claims still hold. It's not really C that has changed (though the language has evolved a little bit), it's the hardware that changed and the implementation of the language.

Re: C Is Not a Low-Level Language

#46

Ok, w/o dipping into machine code, show me a low level language. Any snippet of C-code is transparent in that you know roughly how it is going to be translated into machine code.

Hardware description languages like VHDL, maybe gpu shader languages like CUDA/HLSL

HLSL isn't a low-level language, indeed HL stands for high level. It's not much different than CPU. The runtime compiles down to a standard bytecode, and the driver translates to the GPU's proprietary native code.

Re: C Is Not a Low-Level Language

#47

Going by their definition, I don't think there are any low level languages, at least on modern architectures. Even x86 assembly abstracts out a lot of what is going on within the CPU.

Assembly has been a fiction on most computers for a long time now. From the other side of the instruction decoder, they are more like VLIW machines than evolved 8080's.

Re: C Is Not a Low-Level Language

#48

Ok, w/o dipping into machine code, show me a low level language. Any snippet of C-code is transparent in that you know roughly how it is going to be translated into machine code.

”Any snippet of C-code is transparent in that you know roughly how it is going to be translated into machine code.”

…for a definition of ‘roughly’ that has become significantly less precise over the past decades.

For example, there was a time where you could be reasonably sure every multiplication in your source code mapped to a multiplication instruction, but that time has long been gone. Constant folding, replacement of multiplications by shifts and loop hoisting aren’t exactly novel techniques.

Re: C Is Not a Low-Level Language

#49
The points made in the article are certainly valid, but C is low-level in an abstract sense: it is approximately the intersection of all mainstream languages.

I.e. if a feature exists in C, it probably exists in every language most programmers are familiar with. (I worded this statement carefully to exclude exotic languages like Haskell or Erlang).

Thus C, while not low-level relative to actual hardware, is low-level relative to programmers' mental model of programming. If this is what we mean, it's still true and useful to think of C as a low-level language.

That said, it's important to keep the distinction in mind -- statements like "C maps to machine operations in a straightforward way" have been categorically wrong for decades.

Re: C Is Not a Low-Level Language

#50
post #38

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…

Microcode is the new low level language. ;-) But, to be fair, C is not that low level. In fact, when I first learned it, it was considered a high-level language because CPUs we used it with didn't have functions with parameters, only subroutine jumps. C reaches into the realm of low-level languages because it allows you to arbitrarily read from and write to the "state" of the context you live in, but it also allows y…

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