5 ms·
> C started on 18 bit machines. A program that correctly used "int argc" for the main argument count runs on an 18 bit machine or a 16 bit machine without modif
by lmm 4y ago
> C started on 18 bit machines. A program that correctly used "int argc" for the main argument count runs on an 18 bit machine or a 16 bit machine without modification.
I'm guessing you're too young to remember the 32 -> 64 bit transition, because this is backwards in practice. Non-fixed integer sizes are a nightmare for portability and the reason why some C code still hasn't been ported even today, whereas programs in e.g. Java or OCaml ran without modification on the new machines.
A modern language should make it easy and first-class to use arbitrary-precision integers and decimals though.
- kazinator 4y agoJava programs run without modification on a new machine for basically the same reason why, say, a Nintento Game Boy program runs without modification on an emulator, more or less. The machine has been ported, taking the programs with it, which have not been ported.
- lmm 4y agoNot necessarily; in that era compiling with GCJ was a viable option too. And in the case of something like OCaml there's no VM. The point is that running the program on a different machine does not result in random changes to when arithmetic does or doesn't overflow.
- kazinator 4y agoCompiling doesn't mean you don't have a virtual machine. Don't forget that emulators (good ones) use dyanamic translation techniques. Executor, Valgrind ... (This one: https://en.wikipedia.org/wiki/Executor_(software) https://en.wikipedia.org/wiki/Executor_(software) ) MC68K MacOS software running on x86 via executor has not been "ported", even though it is transpiled to x86 code. That's approximately the same as Java portability. There is a Java virtual machine (whether interpreted or compiled). Programs are written to that, and the virtual machine semantics is what is ported. The programs are running on the Java machine, just like the programs running under Executor are running on a 68K Mac (as far as they know).
- lmm 4y agoC programs also run on the C abstract machine, if you want to use that kind of logic. GCJ was a true native compiler, not an emulator. And Java is far from the only language that offers specific-sized integers. (Even in C, people writing portable code know to avoid the machine-sized integer types and use POSIX intN_t types instead).
- kazinator 4y agoThere is no one C abstract machine; the implementation has to choose parameters and instantiate an abstract machine. The portable C program is a kind polyglot among more than one of these (possibly all).