6 ms·
> The reason I believe C is and always will be important is that it stands in a class of its own as a mostly portable assembler language, offering similar level
by pjmlp 2y ago
> The reason I believe C is and always will be important is that it stands in a class of its own as a mostly portable assembler language, offering similar levels of freedom.
When your computer is a PDP-11, otherwise it is a high level systems language like any other.
- pornel 2y agoLess controversially, when you write C, you write for a virtual machine described by the C spec, not your actual hardware. Your C optimizer is emulating that VM when performing symbolic execution, and the compiler backend is cross-compiling from it. It's an abstract hardware that doesn't have signed overflow, has a hidden extra bit for every byte of memory that says whether it's initialized or not, etc. Assembly-level languages let you write your own calling conventions, arrange the stack how you want, and don't make padding bytes in structs cursed.
- aninteger 2y ago> Less controversially, when you write C, you write for a virtual machine described by the C spec, not your actual hardware. Isn't this true for most higher level languages as well? C++ for instance builds on top of C and many languages call into and out of C based libraries. Go might be slightly different as it is interacting with slightly less C code (especially if you avoid CGO).
- bmandale 2y agoThese are all such nonsensical misinterpretations of what people mean when they say C is "low level". You absolutely don't write C for the C abstract machine, because the C spec says nothing about performance, whereas performance is one of the primary reasons people write C. The existence of undefined behaviour isn't proof that there is a C "virtual machine" that code is being run on. Undefined behaviour is a relaxation of requirements on the compiler. The C abstract machine doesn't not have signed overflow, rather it allows the compiler to do what it likes when signed overflow is encountered. This is originally a concession to portability, since the common saying is not that C is close to assembly, but rather that it is "portable" assembler. It is kept around because it benefits performance, which is again one of the primary reasons people write C.
- pjmlp 2y agoC performance exists thanks to UB, and the value optimising compilers extract out of it, during the 8 and 16 bit home computers days any average Assembly developer could write better code than C compiler were able to spit out.
- codr7 2y agoAnd also because it doesn't get in your way of doing exactly what you want to do.
- OCASMv2 2y agoIf that was true then the optimizers wouldn't need to exist in the first place.
- codr7 2y agoCompared to the alternatives. It gets very frustrating to communicate at this level.
- OCASMv2 2y agoI don't think compilers allowing trash through is a good thing.
- codr7 2y agoThat's an opinion, another one would be that the flexibility allowed by undefined behavior is one of C's strengths at the same time. Strength/weakness are often two sides of the same coin. Which is why these discussions get a bit circular.
- greenavocado 2y agoHave you ever seen the error steamroller? https://github.com/mattdiamond/fuckitjs https://github.com/mattdiamond/fuckitjs
- grandempire 2y agoWhich other popular language more accurately represents a random access machine of fixed word length?
- alexvitkov 2y agoNone, but that'a not what computers are. C assumes that in a few places, e.g. variadic functions, and those are the worst parts of the language.
- grandempire 2y ago> but that'a not what computers are Which language more accurately represents hardware then?
- pjmlp 2y agoAssembly language from the hardware vendor.
- oguz-ismail 2y agoisn't it translated to microcode before being executed?
- pjmlp 2y agoDepends on the hardware design.
- acka 2y ago[flagged]
- sugrado 2y agobro just quoted a chatbot
- 2y ago
- NoTeslaThrow 2y ago> When your computer is a PDP-11, otherwise it is a high level systems language like any other. Describing C as "high-level" seems like deliberate abuse of the term. The virtual machine abstraction doesn't imply any benefits to the developer.
- pjmlp 2y agoNeither does pretending C is a macro Assembler.
- timClicks 2y agoThat's a curious remark, although I guess it doesn't look high level from the eyes of someone looking at programming languages today. C has always been classed as a high level language since its inception. That term's meaning has shifted though. When C was created, it wasn't assembly (middle) or directly writing CPU op codes in binary/hex (low level).
- ecb_penguin 2y ago> Describing C as "high-level" seems like deliberate abuse of the term Honestly it doesn't really matter. High level and low level are relative to each-other (and machine language), and nothing changes based on what label you use. Best thing to do is shrug and say "ok".
- ryao 2y agoSpend 90 days writing nothing but assembly language and then tell me that you believe C is a low level language.
- NoTeslaThrow 2y agoI don't see much difference. What is C suppose to express that assembly cannot? What is assembly suppose to express that C cannot? Does this conversation matter to begin with?
- ryao 2y agoYou did not spend 90 days writing assembly language. I doubt you even spent 1 day.
- hgs3 2y agoCan you elaborate? C constructs generally map to one or a few assembly instructions at most. You can easily look at C and predict the generated assembly. This is in contrast to other compiled languages, like Go, that inject instructions for garbage collection and other runtime features.
- pjmlp 2y agoSee my list of languages on a sibling thread, same applies to those, nothing special about C there.
- uecker 2y agoWhile C was adapted to the PDP-11, this was adding byte-level memory access. Otherwise I do no think there is anything in C specific to the PDP-11, or what would this be? What makes C low-level is that it can work directly with the representation of objects in memory. This has nothing to do with CPU features, but with direct interoperability with other components of a system. And this is what C can do better than any other language: solve problems by being a part of a more complex system.
- WalterBright 2y agoThe post-increment and post-decrement operators mapped directly onto PDP-11 CPU addressing modes. The integral promotion rules come directly from the PDP-11 CPU instruction set. If I recall correctly so does the float->double promotions. CPUs started adapting to C semantics around the mid-80's. CPU designers would profile C generated code and change to be able to more efficiently run it.
- uecker 2y agoThanks. I guess the integral promotion is related to byte-addressing. If you have bytes but can not directly do arithmetic on them, promoting them to word size seems natural.
- codr7 2y agoYeah, people keep repeating that like a broken record lately, it smells like Rust to me. No one is claiming it was built for today's processors, just that it puts less obstacles between you and the hardware than almost any other language. Assembler and Forth being the two I'm familiar with.
- pjmlp 2y agoBecause people keep repeating the urban myth of portable assembler and being the very first systems programming language. One of the very first systems programming languages was JOVIAL, from 1958. C's inventors were still finalising their studies.
- codr7 2y agoI don't know how to phrase this to reach through, but you're barking up the entirely wrong tree. It's not about the CPU, it's about the level of freedom afforded by the language; how close to hardware it allows you to go, how few hoops you have to jump trough to get there. The other approach, taken by Rust (and to some degree C++), is to nail everything to the floor and force the programmer to express a solution in a specific format that's easier to verify and make guarantees about. Which is fine. Both approaches have their appeal, which is best depends on context.
- pjmlp 2y agoWhich is again nothing special about C, other languages offer similar capabilities, I have provided a list in a sibling comment. Keep waiting for the examples where they can't do what ISO C allows for, and if the example uses compiler extensions to the ISO C, I also feel within the right to use extensions to those languages on the counter example.
- _kst_ 2y agoC is a relatively low level language, but it is not assembly language. The difference is clear. Assembly language programs specify sequences of CPU instructions. C programs specify runtime behavior.