2

I've found a programming tool called emscripten that can compile c++ code to Javascript code using LLVM. Is it possible to compile C to Javascript using Emscripten (or a similar tool?)

JasonMArcher
  • 13,296
  • 21
  • 55
  • 51
Anderson Green
  • 27,734
  • 61
  • 179
  • 311

1 Answers1

1

Emscripten doesn't know a thing about C++. It operates on LLVM IR, and cares relatively little how that code was created. You can compile just about anything (that has a LLVM-IR-emitting compiler), including C++, to LLVM IR and pass that to Emscripten.

Note that the result is highly unlikely to resemble human-written JavaScript, and will be unfit for maintenance and further development. It also has some inherent restrictions -- JavaScript isn't machine code, and even if it was, it wouldn't necessarily be compatible to the assumptions of some low-level code.