surprising semantics of the && expression

Timon Gehr timon.gehr at gmx.ch
Tue Feb 3 20:15:42 UTC 2026


On 2/3/26 18:29, user1234 wrote:
> So yesterday someone oppened an issue:
> 
> https://github.com/dlang/dmd/issues/22500
> 
> Which was closed after accurate explanations of Ian. However I'd like to 
> know where this semantics are coming from. I suspect C++ ? What is the 
> history behind ?
> ...

C is not very type safe (and used to be even less so), and people get 
attached to idioms.

> Let's mention the POLA. The very basic human-being would expect that 
> both the LHS and RHS sub-expressions can be implictly convertible to 
> `bool`.
> 
> 

That is not true anyway. ;p

```d
int foo(){ ... }

bool a = foo()&&foo(); // ok
bool b = foo(); // not ok
```

(It requires explicit convertibility, not implicit.)

A common shorthand in D for `cast(bool)e` is `!!e`.
`assert(c)` for class reference `c` used to segfault on `null`. I still 
consistently write `assert(!!c)` today.


More information about the Digitalmars-d mailing list