4 ms·
Well, C is essentially "portable assembly", so it's to be expected...
by jballanc 11y ago
Well, C is essentially "portable assembly", so it's to be expected...
- boomlinde 11y agoI never understood this sentiment. C isn't assembly exactly because there isn't necessarily a direct correlation between the instructions the programmer writes and the resulting machine code. To me, this is as contrived as the idea that Javascript is "LISP in Java's clothing" In what possible sense can it be described as an assembler?
- nemothekid 11y ago>because there isn't necessarily a direct correlation between the instructions the programmer writes and the resulting machine code If there was, then it wouldn't be "portable"
- boomlinde 11y agoMy point is that if you choose to ignore this characteristic of assembly languages, what exactly is an assembly language? C is a comparably high level language, which affords it things like portability and optimizing compilers. Assembly languages are used for minute and immediate control of the exact implementation.
- nemothekid 11y ago>Assembly languages are used for minute and immediate control of the exact implementation. I think the joke/humor/analogy is that C compilers are so good and C itself is so low level, that you don't actually gain much (if anything at all) by dropping down to ASM now (compared to 10-20 years ago).
- sukilot 11y agoThere is very little difference to the machine code (traditionally, before CPUs got so complex)
- boomlinde 11y agoI'm not sure what you are saying here. Do you mean to say that it makes no difference to the machine how the code is generated, or are you saying that there is a CPU for which there is "little difference" between its machine code and C?
- sukilot 11y agoThere is very little difference to the machine code (traditionally, before CPUs got so complex)
- evincarofautumn 11y agoIt’s relatively easy to mentally compile unoptimised C, or to look at an unoptimised assembly listing and correlate it with the source, but that’s about as far as the metaphor goes. C is a high-level language. Only when I’m writing very performance-sensitive code do I actually think “here’s a branch, there’s a load, yonder is a divide”. Most of the time it’s “eh, compiler’ll get it”.
- the_why_of_y 11y agoBecause C is a very low level language, it imposes very little architectural decisions on higher levels that could cause impedance mismatches. For example, you wouldn't want to implement a garbage collector in a garbage collected language; C won't get in your way. This is also why there are loads of C libraries out there: they can be used with bindings from essentially any other language, which is generally not true for libraries implemented in non-C languages (in particular, C++).
- boomlinde 11y ago> Because C is a very low level language, it imposes very little architectural decisions on higher levels that could cause impedance mismatches. Remember that it also enforces the idea of types, scopes, blocks, functions, the heap and the data stack quite strictly. It might be a very low level language compared to something like Java, but in terms of being unassuming of architectural intent, I can't say that I agree that it is even in the same ballpark as any of the assembly languages I've used.
- the_why_of_y 11y agoIndeed it enforces some function calling convention, which may be an issue if you want to compile a high level language via C, particularly since C does not guarantee tail call optimization. Also there's no fast way to check arithmetic overflow from portable C, which limits bignum performance. Due to these limitations better portable assembly languages like C-- have been designed; these days LLVM bitcode is an option as well (which is not actually portable IIRC...).
- pacifist 11y agoMaybe not a direct correlation but: "By design, C provides constructs that map efficiently to typical machine instructions"[1] I believe this is what the op was getting at. This is why C is called a "mid level" language. [1] http://en.wikipedia.org/wiki/C_%28programming_language%29 http://en.wikipedia.org/wiki/C_%28programming_language%29
- munificent 11y agoI think these days the term "portable assembly" misses the mark. A term that better captures the flavor of C with today's CPUs is "programmable RAM". C is one of the few languages today that still gives you very precise control over how you use memory. That can be a powerful tool, especially given how important effective cache usage is on chips.