Doubt about char.min/max == typeid(char)
bauss
jacobbauss at gmail.com
Fri Oct 7 05:06:30 UTC 2022
On Friday, 7 October 2022 at 04:40:26 UTC, matheus wrote:
>
> Hmm well I was thinking the min/max as a range/limits, in this
> case 0 to 255 or it could be -128 to 127 if signed
char casts implicitly to int, so if you really need it as an
integer type just type your variable as such.
```d
int a = char.max; // valid.
```
If you don't need to assign it then you can cast it.
```
void a(int x) { ... }
a(cast(int)char.max);
```
Even though in the example above the cast isn't necessary, if you
want to be sure a(int) is called then you must cast it, since an
overload of char will obviously be picked.
>, or in a
> case of a bool: 0 to 1, but now I see it returns the min/max
> value of the type itself, like the latter false/true.
>
The same applies for a bool.
> I had my reasoning based on my experience with C.
>
D isn't C, so you can't really compare it 1:1, even though a lot
of C rules apply to D, then all of them doesn't.
This is one of the places where it improves on top of it, because
generally you don't want your min/max to be different types, but
you can implicitly get the integer behavior if you desire so.
More information about the Digitalmars-d-learn
mailing list