News for hackers. Stuff that matters.
Re:C++ proposal: There are 8 bits in a byte by pezezin on Thursday October 17, 2024 @10:51PM (#41875953)
If you don't care about the size of your number, just use isize or usize.

If you do care, then isn't it better to specify it explicitly than trying to guess it and having different compilers disagreeing on the size?

Re:C++ proposal: There are 8 bits in a byte by kazinator on Thursday October 17, 2024 @10:54PM (#41875968)
A type called isize is some kind of size. It looks wrong for something that isn't a size.
Re:C++ proposal: There are 8 bits in a byte by pezezin on Friday October 18, 2024 @12:46AM (#41876423)
Then just define a type alias, which is good practice if you want your types to be more descriptive: https://doc.rust-lang.org/reference/items/type-aliases.html
Re:C++ proposal: There are 8 bits in a byte by kazinator on Friday October 18, 2024 @02:55AM (#41876975)
Nope! Because then you will also define an alias, and Suzy will define an alias, and Bob will define an alias, ...

We should all agree on int and uint; not some isize nonsense, and not bobint or suzyint.

Re:C++ proposal: There are 8 bits in a byte by pezezin on Friday October 18, 2024 @03:46AM (#41877189)
Ok, it is obvious that you are looking for something to complaint about and don't want to find a solution. That is not a productive attitude in life, but whatever floats your boat. Have a good day.
Re:C++ proposal: There are 8 bits in a byte by kazinator on Friday October 18, 2024 @02:26PM (#41882105)
> looking for something to complaint about

You know, that describes pretty much everyone who has anything to do with Rust.

"My ls utility isn't written in Rust, yikes! Let's fix that!"

"The comments under this C++-related HN submission aren't talking about Rust enough, yikes! Let's fix that!"

I'm obviously pointing to a solution: have a standard module that any Rust program can depend on coming from the language, which has a few sanely named types. Rather than every program defining its own.

Re:C++ proposal: There are 8 bits in a byte by jclulow on Friday October 18, 2024 @03:23AM (#41877079)
Alas, it's pretty clear that we won't!
Re:C++ proposal: There are 8 bits in a byte by hahamaster on Friday October 18, 2024 @07:56PM (#41884530)
You insist that we should all agree on something but you don't specify what.
Re:C++ proposal: There are 8 bits in a byte by heinrich5991 on Friday October 18, 2024 @05:41AM (#41877751)
Actually, if you don't care about the size of your small number, use `i32`. If it's a big number, use `i64`.

`isize`/`usize` should only be used for memory-related quantities — that's why they renamed from `int`/`uint`.

Re:C++ proposal: There are 8 bits in a byte by kazinator on Friday October 18, 2024 @02:29PM (#41882127)
If you use i32, it looks like you care. Without studying the code, I can't be sure that it could be changed to i16 or i64 without breaking something.

Usually, I just want the widest type that is efficient on the machine, and I don't want it to have an inappropriate name. I don't care about the wasted space, because it only matters in large arrays, and often not even then.

Re:C++ proposal: There are 8 bits in a byte by heinrich5991 on Friday October 18, 2024 @04:59PM (#41883443)
> If you use i32, it looks like you care.

In Rust, that's not really the case. `i32` is the go-to integer type.

`isize` on the other hand would look really weird in code — it's an almost unused integer type. I also prefer having integers that don't depend on the machine I'm running them on.

Re:C++ proposal: There are 8 bits in a byte by kazinator on Friday October 18, 2024 @09:03PM (#41884813)
Some 32 bit thing being the go to integer type flies against software engineering and CS.

It's going to get expensive on a machine that has only 64 bit integers, which must be accessed on 8 byte aligned boundaries.

Re:C++ proposal: There are 8 bits in a byte by pezezin on Saturday October 19, 2024 @09:37PM (#41892216)
And which machine is that? The only computers that I can think of with only 64-bit integers are the old Cray vector supercomputers, and they used word addressing to begin with.
Re:C++ proposal: There are 8 bits in a byte by kazinator on Monday October 21, 2024 @02:02AM (#41901093)
It will likely be common in another 25 to 30 years, as 32 bit systems fade into the past.

Therefore, declaring that int32 is the go to integer type is myopic.

Forty years ago, a program like this could be run on a 16 bit machine (e.g. MS-DOS box):

  #include <stdio.h>

  int main(int argc, char **argv)
  {
    while (argc-- > 0)
      puts(*argv++);
    return 0;
  }
int was 16 bits. That was fine; you would never pass anywhere near 32000 arguments to a program.

Today, that same program does the same thing on a modern machine with a wider int.

Good thing that some int16 had not been declared the go to integer type.

Rust's integer types are deliberately designed (by people who know better) in order to be appealing to people who know shit all about portability and whose brains cannot handle reasoning about types with a bit of uncertainty.

Re:C++ proposal: There are 8 bits in a byte by pezezin on Monday October 21, 2024 @04:08AM (#41901792)
Sorry, but I fail to see where the problem is. Any general purpose ISA designed in the past 40 years can handle 8/16/32 bit integers just fine regardless of the register size. That includes the 64-bit x86-64 or ARM64 from which you are typing.

The are a few historical architectures that couldn't handle smaller integers, like the first generation Alpha, but:

    a) those are long dead.

    b) hardware engineers learnt from their mistake and no modern general purpose architecture has repeated it (specialized architectures like DSP and GPU are another story though).

    c) worst case scenario, you can simulate it in software.