Hacker News new | ask | show | jobs
by the8472 3597 days ago
Some people treat C as portable assembly.

Does that make gcc a transpiler for converting portable assembly to platform-specific assembly due to their similar semantics?

1 comments

I knew someone would bring this up.¹

GCC is an optimizing compiler, at which point all bets are off for obvious/trivial translation between C and asm. You could, hypothetically, write a optimizing TypeScript compiler that emits asm.js.

However, while you can reasonably argue C started as a portable assembly, significant differences like a type system, pointer arithmetic, a calling convention, etc, exist now. I don't think it's unreasonable to say C is significantly higher-level than assembly.

1. My parenthetical at the end was anticipating this—then again, the translation between C and asm frequently is easy, albeit tedious.

I guess you could replace gcc with a dumb compiler / turn off optimizations. And throw in compiler intrinsics while we're at it, after all people write hot loops with them. And pointer arithmetics actually translate nicely to all those fancy addressing modes you find on x86.

And in the other direction one could argue that those so-called "transpilers" actually compile from a higher-level language when you consider complex type-inference and static type checking. Optimizing is not all a compiler does.