Live data from Hacker News

C Is Not a Low-Level Language

queue.acm.org

151–160 of 326 posts

Re: C Is Not a Low-Level Language

#151
post #141

Earlier quoted context omitted.

This argument has been made since the introduction of the JVM in the early mid-90's. Seems to me like if, in practice, JIT provided better performance then by now people would be rewriting their C/C++ code in Java and C# for speed.

> Seems to me like if, in practice, JIT provided better performance then by now people would be rewriting their C/C++ code in Java and C# for speed. It's a little bit faster, not faster by enough to matter. If you're going to rewrite C/C++ code for speed you'd go to Fortran or assembler, and even then you're unlikely to get enough of a speedup to be worth a rewrite. New projects do use Java or C# rather than C/C++ th…

"New projects do use Java or C# rather than C/C++ though."

But not for speed reasons. Java is in no way faster than well written C/C++

Re: C Is Not a Low-Level Language

#152

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.

unsigned char r(unsigned char num) { return num % 10; } https://godbolt.org/g/26HfQk

What you see there is the insane amount of complexity to create a high level feature of C: functions, plus compiler optimizations.

What I don't understand about this argument is that you are calling C a high-level language because of compiler optimizations. I can write code in assembler, or in LLVM SSA, and still use software to optimize it beyond recognition.

Re: C Is Not a Low-Level Language

#154

Earlier quoted context omitted.

Actually, the author's argument about PDP-11 is interesting because C would have never been considered a low level language back then, for any platform. Wiki definition, also what I was taught in my first CS class: "A low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture—commands or functions in the language map closely to proces…

> Actually, the author's argument about PDP-11 is interesting because C would have never been considered a low level language back then, for any platform. Sure, agreed, but I don't think it's super interesting that words evolve in meaning over time. What I find strange about the comments here is that some people think the article's title is bad even though my experience is that many people today do think "C is a low…

I guess I'm arguing that it is a reasonable thing to say today in the right context. When I talk to web developers who don't understand anything about computer architecture for example it's much easier for me to tell them I'm a low level developer rather than explain that I design digital hardware (FPGA) and write drivers and firmware to interact with it. But I do agree that it's important developers know that C doesn't correspond to the CPU in the way they might mistakenly think it does

Re: C Is Not a Low-Level Language

#155

This doesn't make any sense. This would mean that my C code compiled for a Cortex-M0 is low level, but for my x86 laptop is not. Or even more stupid, that the same assembly code running in an old 386 is low level, but for an i7 isn't. Low level is about how close to talking to the CPU you are, not about how close to the silicon you are. The CPU is a black box and the programmer communicates with it. What that box doe…

Also, various C interpreters exist where there is no explicit C —> assembly translation.

Re: C Is Not a Low-Level Language

#156
post #145

Language evolves. C is certainly lower level than C# or JavaScript, so even if it no longer fits the definition created decades ago, I don't see a problem with the term evolving to match modern times. People say assembly language when they mean assembly language, (which others have argued isn't low level any more anyway) so using low level to describe a language closer to the hardware seems valid to me. It's interest…

The whole point of the article is that by a definition like the one you quoted, modern C is not low-level, though PDP-11 era C was.

Except what I'm saying is that PDP-11 era C wasn't low level. It incedentally took advantage of some low level features, but that wasn't by design, and wouldn't have changed its classification as a high level language at the time anyway

Re: C Is Not a Low-Level Language

#157
> The root cause of the Spectre and Meltdown vulnerabilities was that processor architects were trying to build not just fast processors, but fast processors that expose the same abstract machine as a PDP-11. [...]

This strikes me as a flavor of the VLIW+compilers-could-statically-do-more-of-the-work argument, though TFA does not mention VLIW architectures.

C or not, making compilers do more of the work is not trivial, it is not even simple, not even hard -- it's insanely difficult, at least for VLIW architectures, and it's insanely difficult whether we're using C or, say, Haskell. The only concession to make is that a Haskell compiler would have a lot more freedom than a C compiler, and a much more integrated view of the code to generate, but still, it'd be insanely hard to do all of the scheduling in the compiler. Moreover, the moment you share a CPU and its caches is the moment that static scheduling no longer works, and there is a lot of economic pressure to share resources.

There are reasons that this make-the-compilers-insanely-smart approach has failed.

It might be more likely to be successful now than 15 years ago, and it might be more successful if applied to Rust or Haskell or some such than C, but, honestly?, I just don't believe this will work anytime soon, and it's all academic anyways as long as the CPU architects keep churning out CPUs with hidden caches and speculative execution.

If you want this to be feasible, the first step is to make a CPU where you can turn off speculative execution and where there is no sharing between hardware threads. This could be an extension of existing CPUs.

A much more interesting approach might be to build asynchrony right into the CPUs and their ISAs. Suppose LOADs and STOREs were asynchronous, with an AWAIT-type instruction by which to implement micro event loops... then compilers could effectively do CPS conversion and automatically make your code locally async. This is feasible because CPS conversion is well-understood, but this is a far cry from the VLIW approach. Indeed, this is a lot simpler than the VLIW approach.

TFA mentions CMT and ULtraSPARC, and that's certainly a design direction, but note that it's one that makes C less of a problem anyways -- so maybe C isn't the problem...

Still, IMO TFA is right that C is a large part of the problem. Evented programs and libraries written in languages that insist on immutable data structures would help a great deal. Sharing even less across HW/SW threads (not even immutable data) would still be needed in order to eliminate the need for cache coherency, but just having immutable data would help reduce cache snooping overhead in actual programs. But the CPUs will continue to be von Neuman designs at heart.

Re: C Is Not a Low-Level Language

#158
post #145

Language evolves. C is certainly lower level than C# or JavaScript, so even if it no longer fits the definition created decades ago, I don't see a problem with the term evolving to match modern times. People say assembly language when they mean assembly language, (which others have argued isn't low level any more anyway) so using low level to describe a language closer to the hardware seems valid to me. It's interest…

The whole point of the article is that by a definition like the one you quoted, modern C is not low-level, though PDP-11 era C was.

That's not true - PDP-11 era C isn't either - if you run it on a modern processor. And it's doubtful it even was then.

Re: C Is Not a Low-Level Language

#159

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. This isn't really true on a modern optimizing compiler.

But this will never be true in any low level language. You can spend a lot of time optimizing any single line of code manually, but software will always be faster than you. And will optimize any code you write beyond recognition.

Re: C Is Not a Low-Level Language

#160
The sophistication of the compiler does not mean the language is high level.

The meaning of a high level language is to do with abstraction away from the hardware. C programmers often wince at languages that are highly abstracted away from the hardware. But those are what are "high level" languages. Especially languages that remove more and more of the mechanical bookkeeping of computation. Such as garbage collection (aka automatic memory management). Strong typing or automatic typing. Dynamic arrays and other collection structures. Unlimited length integers and possibly even big-decimal numbers of unlimited precision in principle. Symbols. Pattern matching. Lambda functions. Closures. Immutable data. Object programming. Functional programming. And more.

By comparison C looks pretty low level.

Now I'm not knocking C. If there were a perfect language, everyone would already be using it. Consider the Functional vs Object debate. (Or vi vs emacs, tabs vs spaces, etc) But all these languages have a place, or they would not have a widespread following. They all must be doing something right for some type of problem.

C is a low level language. And there is NOTHING wrong with that! It can be something to be proud of!

Post reply on HN