5 ms·
I feel, low to high level is a spectrum, not a binary. C is arguably in the lowest third of languages, exposing you to a lot of machine primitives like memory a
by wolframhempel 3y ago
I feel, low to high level is a spectrum, not a binary. C is arguably in the lowest third of languages, exposing you to a lot of machine primitives like memory and thread management. It may not be as low level as assembly, but it is arguably lower level than Java or Go, and definitely nowhere near the Pythons and JS of this world.
- Joker_vD 3y ago> exposing you to a lot of machine primitives like memory and thread management Except it doesn't really, the standard leaves most of the really machine-dependent parts undefined; only very few things are left implementation-defined. Plus, of course, C is quite unsuitable for any platform that uses segmented memory/non-flat addresses (which are things that are trying to come back in vogue but C's wide spread really, really hinders that).
- mytailorisrich 3y ago> Except it doesn't really, the standard leaves most of the really machine-dependent parts undefined Well that's because it is low level and, especially, simple, and doesn't try to abstract things.
- TheOtherHobbes 3y agoIt's a certain kind of low level - specifically a PDP-11 kind of low level. If your hardware is significantly different, it only looks low level. In reality plenty of mapping and conversion goes on behind the scenes - sometimes with hilarious consequences.
- pornel 3y ago> and doesn't try to abstract things. The C standard is a description of an abstract machine. You get UB and unexpected miscompilations, because the optimizer is not evaluating how your code runs on the machine you're compiling for, but simulates running your code on the weirdly abstract C machine, one that can't overflow signed integers. And C abstracts away almost everything about stack, stack frames, and all the complexities of memory and cache hierarchies. They are abstracted to be uniform linear address space.
- mrpopo 3y agoCan you or someone expand further on that? Which platforms are trying to use segmented addressing, and what benefits does it have?
- Joker_vD 3y agoCHERI project [0]. Look at figure 2.1: it's an improvement and further development of the segments of yore but the origins are quite visible. [0] https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-941.pdf https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-941.pdf
- saagarjha 3y agoC supports CHERI quite well. It’s modern languages used to flat address spaces and 64-bit pointers that are having a hard time, because they defined a lot of “obvious” behaviors that the standard leaves flexible.
- robmccoll 3y agoBy that do you mean exposing a non-uniform memory hierarchy as separate addressable spaces (but with coherent views from each hardware thread) or something like thread-local scratch pads? Either way, C is equipped ok for that - at least as well as most systems languages C++, Rust, etc. - simply because dealing with allocation and raw addressing (at least raw within the process memory space) is a fundamental part of the experience. Throw in a few compiler extensions (because you'll need to change the compiler to make use of this anyway) for things like where to locate static allocations and use library functions that add dynamic allocation in specific spaces. It will get hairy, but it's at least possible with some very careful programming.
- agentultra 3y agoWe did ok with the 8086 processors, no?
- Joker_vD 3y agoYes, juggling near and far pointers was somewhat annoying but then Intel, as a part of the 32-bit transition, modified their ISA to be a more pleasant target for C implementations. Incidentally, C never really became popular on 6502 because, arguably, that ISA is somewhat hostile towards efficient implementations of higher-level languages.
- actionfromafar 3y agoLisp is fine on 6502 though :-)
- agentultra 3y agoTrue. The code generated by https://cc65.github.io/ https://cc65.github.io/ is pretty decent but there are a few places where hand-rolled assembler will perform much better when you need it. Although I've made things for 6502-based systems in C with this handy compiler (thanks cc65 contributors!). Is there something intrinsic to how C handles addressing that makes segmented architectures more painful than they ought to be? Or maybe is there a language where segmented addressing is easier? I hadn't really thought about it in a while. :)
- eesmith 3y ago1990 is calling: "C does not behave as a typical ‘high-level’ language, because it offers a number of features which are more normally associated with ‘low-level’ languages such as assembly language. These include the ability to write data to and from particular memory addresses, facilities for operations on the contents of memory locations, and instructions for incrementing and decrementing integer variables ... Thus C allows the programmer the flexibility and efficiency of working at low level with the advantages of working at high-level, for example the more advanced data structures and program flow controls typical of today’s computer languages. For this reason, C is sometimes described as a ‘high-level low-level language’ or as a ‘low-level high-level language’." - https://archive.org/details/computerprogramm0000ford/page/138/mode/2up?q=%22low-level+high-level+language%22 https://archive.org/details/computerprogramm0000ford/page/13...
- danielvaughn 3y agoHonest question - is there any language at all between C and Assembly? Because if there is, I haven't heard of it. For that reason alone, my mental model has always been "C is the lowest you can go before hitting direct instructions to the processor."
- lebuffon 3y agoI would say Forth is lower level than C. The mental model is a two stack machine plus memory, rather than a PDP-11. And it is very reasonable if you are under 50 years of age, that you haven't heard of it.
- jeffreygoesto 3y agoStarted programming 81 and technically I could have known it https://www.timexsinclair.com/product/zx-forth/ https://www.timexsinclair.com/product/zx-forth/
- xigoi 3y ago> is there any language at all between C and Assembly? LLVM or QBE, for example.
- fiedzia 3y agoConceptually, you can consider LLVM IR to be such language, and there are people who use it that way.
- grotorea 3y agoThere are some cleverer assemblers that allow to program in assembly while still being able to do stuff like loops without too much effort https://en.wikipedia.org/wiki/Assembly_language#Support_for_structured_programming https://en.wikipedia.org/wiki/Assembly_language#Support_for_...
- CJefferson 3y agoC makes lots of things undefined behavior which are perfectly fine in assembler — read a stack without first writing to it, doing overflow signed internet arithmetic, treating the same memory location as different types. Also there is quite a lot in modern assembler that you can’t really get to from C, like prefetch and cache flushing instructions.
- clnq 3y agoYou have high expectations for accuracy in an article titled "C Is Not a Low-level Language".