3 ms·
> The idea that you can have a language which is portable/reimplementable on any platform is fundamentally flawed. You can't. If you can't implement C on a pla
by jdmichal 11y ago
> The idea that you can have a language which is portable/reimplementable on any platform is fundamentally flawed. You can't.
If you can't implement C on a platform, I think you're in some pretty strange territory and you're probably having to invent your own language to match the platform.
- djpowell 11y agoWhat if the platforms are the JVM and Javascript, and you are chosing those platforms because of their extensive infrastructure and libraries? It is possible to implement C faithfully on these platforms, including all of C's weirdness like pointer-arithmetic and unsafe casting. But you'd end up with something that departs far from the platform's runtime model and calling conventions.
- jdmichal 11y ago> It is possible to implement C faithfully on these platforms, including all of C's weirdness like pointer-arithmetic and unsafe casting. Of course it can. The two platforms you listed can both faithfully emulate an entire computer, upon which you can build your C runtime. http://bellard.org/jslinux/ http://bellard.org/jslinux/ http://bellard.org/jslinux/tech.html http://bellard.org/jslinux/tech.html Now, if what you really meant was more along the lines of "can I faithfully cross-compile C to Java bytecode", the answer would be "not without a layer of abstraction".
- bad_user 11y agoYou couldn't have given a better example. C as a language doesn't have a standard library, with the standard library being Win32, or whatever comes on POSIX/Unix systems these days. You even get a different libc on Android, which isn't glibc, so with its own quirks and bugs. Win32 doesn't do fork and I/O is very different. And on embedded systems you're going to work with a C subset. And each compiler has special extensions. In other words what you call C is actually very different from platform to platform, people solving that with a crap load of ifdef statements.
- jdmichal 11y agoNo, what I call C is the same on every platform. Otherwise, all those "crap load of ifdef statements" wouldn't work. What is called the C standard library on each platform is different, because as you said C itself does not define a standard library. So yes, I did pick my example very appropriately.