5 ms·
That's another thing. I don't want to see 32 and 64 crap in code that is supposed to be high level and portable. i32 means I'm doing FFI with C libraries. If
by kazinator 4y ago
That's another thing. I don't want to see 32 and 64 crap in code that is supposed to be high level and portable.
i32 means I'm doing FFI with C libraries.
If you check the Rust documentation, you see it has no integer types that are not a fixed size.
"All the world is x86/ARM (formerly DEC VAX / Sun SparcStation )"
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.
- 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).
- the_mitsuhiko 4y agoNot once did I want a magically differently sized integer. But if you do, Rust has these.
- adrianN 4y agoI on the other hand like that _int_ doesn't mean "some integer of implementation defined width". I want to know for sure how big my numbers can be and how much memory an array of such numbers consumes.
- timlatim 4y agoPersonally, I struggle to see what's good about unspecified-but-fixed-width integer types as in C/C++. A lot of real-world code I see uses uint32_t (sometimes typedef'd to u32) and the like to get predictable data layout and to avoid cute gotchas like long being 64-bit on x86_64 Linux but 32-bit on Windows. I also like how Rust makes both signed and unsigned types equally easy to type, because I feel that a lot of people use signed integers where they should be using unsigned simply because it's easier to type "int" compared to "unsigned (int)". And if you absolutely need a machine word size dependent type in Rust, you do have usize, which is the equivalent of size_t.
- imtringued 4y agoI am seriously confused. Using fixed size integers is about correctness. Randomly changing the size of your integers will cause unexpected integer overflows. I16 and I64 is more concise than short and long and it is immediately obvious what the number range is for a beginner. The only complaint regarding portability is the unstated assumption that every computer can only store two values per bit. A hypothetical QLC based computer might store a I64 number in 32bits.
- kazinator 4y agoYou know you're dealing with a goofball C programmer when you have code with some small array like: unsigned char buf[1024]; and the index being used to walk over the buffer is uint16_t rather than just plain old int. When I look at Rust code and see all the 32 and 64, it's triggering my bozo switch. It's clear who they are trying to attract, in any case.
- ssokolow 4y agoWhich is why Rust has `usize` for indexes and memory offsets. Beyond that, a good programming language can't fix a bad programmer. Were you aware that, because people use `int` so liberally, the LLP64 model 64-bit Windows uses and the LP64 model Linux, macOS, and the BSDs use keep `int` 32-bit on 64-bit platforms? Hello, risk of integer overflow. LLP64 even keeps `long` at 32-bit. https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_m... It turned out that the C approach was so bad for portability in practice that it de-facto standardized `int` as 32 bits wide.
- kazinator 4y agoThe C standard describes an int type whose minimum range is -32767 to 32767. Any programmer worth their salt knows this. If writing maximally portable code, they either stick to that assumption or else make some use of INT_MIN and INT_MAX to respect the limits. The minimum range is adequate for all sorts of common situations. Some 32 bit targets had 16 bit int! E.g. this was a configuration for the Motorola 68K family, which has 32 bit address and 32 bit data pointers. See the "-mshort" option of GCC, documented here: https://gcc.gnu.org/onlinedocs/gcc/M680x0-Options.html https://gcc.gnu.org/onlinedocs/gcc/M680x0-Options.html > It turned out that the C approach was so bad for portability in practice that it de-facto standardized `int` as 32 bits wide. And, so, Rust builds on that by renaming that to i32, to further entrench the poor practices. Of course, you will not win any popularity contest by appealing to people who know what they are doing, who are the minority.