bool <=> int. WTF. (DIP0015)

Exil Exil at gmall.com
Tue Jul 2 16:24:07 UTC 2019


On Tuesday, 2 July 2019 at 12:06:00 UTC, a11e99z wrote:
> import std;
>
> enum E : int { zer, one, two };
>
> auto fn( long a ) { writeln( typeof(a).stringof, " ", a ); 
> return a; }
> auto fn( bool a ) { writeln( typeof(a).stringof, " ", a ); 
> return a; }
>
> void main() {
>     writeln( typeof(0).stringof, " ", 0.sizeof );
>     writeln( typeof(1).stringof, " ", 1.sizeof );
>     writeln( typeof(E.two).stringof, " ", E.two.sizeof );
>
>     fn( 0 );
>     fn( 1 );
>     fn( 2 );
>     fn( E.zer );
>     fn( E.one );
>     fn( E.two );
> }
>
>
> prints:
>>>>>>>>>>>>>>>>>>>>
> int 4
> int 4
> E 4
> bool false
> bool true
> long 2
> bool false
> bool true
> long 2
> <<<<<<<<<<<<<<<<<<<
>
> first WTF?
> why called with bool? 1 is int32 as D printed. E is at least 
> int2 but with explicitly base type as int it is int32 too.
> why bool?
> why D ignores integral promotion that moves to bigger size or 
> unsigned same size?
>
> okey. probably bool is int1 and finita la comedia! (one man 
> (Simon?) says that)
>
> bool b = 0;
> writeln( ++b ); // Error: operation not allowed on bool b += 1
>
> second WTF?
> so, what bool is?
> is this int1? why others promotes to less size and why disallow 
> ++ for int1?
> is this a "real" boolean? why others promotes to it?
>
> imo
> - if some datatypes used as condition they implicitly converts 
> to bool - ok
> - funcs that accept bools should be checked/searched in the end 
> as last choice. in case where exists other alternatives to bool 
> it should be selected.
>
> Please make a system for voting. Give to Walter 100 votes but 
> not 99% of all votes as it is now. And let's vote for adequate 
> non brainf*king behavior.

https://www.youtube.com/watch?v=cpTAtiboIDs#t=2h17m50s

This isn't likely to change.

Some more discussion here:

https://forum.dlang.org/thread/bareupbeyubtmyorxqcz@forum.dlang.org?page=1






More information about the Digitalmars-d mailing list