surprising semantics of the && expression
Timon Gehr
timon.gehr at gmx.ch
Wed Feb 4 09:20:13 UTC 2026
On 2/3/26 23:34, Forum User wrote:
> On Tuesday, 3 February 2026 at 20:15:42 UTC, Timon Gehr wrote:
>> 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.
>
> Sure, but in C (as in C++) with int b and void foo ()
>
> b && foo ();
>
> is not an idiom. It does not compile.
>
Why declare the return type as `void` when you could just claim it is
`int` instead.
Compiles as C as well as D:
```c
auto foo(){}
void main(){
int b = 1;
b && foo();
}
```
More information about the Digitalmars-d
mailing list