bool <=> int. WTF. (DIP0015)

Era Scarecrow rtcvb32 at yahoo.com
Thu Jul 4 22:01:20 UTC 2019


On Thursday, 4 July 2019 at 16:31:11 UTC, Patrick Schluter wrote:
> that's the issue. D's bool type follows exactly C (C has bool 
> since C99) and C++ way.

  Could always make a new type that's strictly 1 bit and not 
implicitly converted with only 2 possible values.

  Then the compiler may use the original bool or the new bool, 
depending on compiling optimizations if it would make a 
difference.

  But honestly, i kinda like the C/C++ way, since it then makes it 
easy to do if statements for results and pointers rather than 
explicitly comparing != null on every pointer/use of it. And 
you're basically ensuring non-zero and non-false in that case.

  Opcode-wise, usually a simple bool check is 'test eax,eax' which 
will give a Z/NZ flag and you do a jump (jz/jnz) from there.

  Having it behave like C/C++ is... well... quite wide-reaching 
and accepted. I don't see the point in deviating from that.


More information about the Digitalmars-d mailing list