bool <=> int. WTF. (DIP0015)

a11e99z black80 at bk.ru
Tue Jul 2 12:06:00 UTC 2019


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.


More information about the Digitalmars-d mailing list