surprising semantics of the && expression

Timon Gehr timon.gehr at gmx.ch
Wed Feb 4 20:06:55 UTC 2026


On 2/4/26 19:08, Walter Bright wrote:
> On 2/4/2026 1:20 AM, Timon Gehr wrote:
>> Compiles as C as well as D:
>>
>> ```c
>> auto foo(){}
>>
>> void main(){
>>      int b = 1;
>>      b && foo();
>> }
>> ```
> 
> ```c
> int foo() { }
> ```
> 
> compiles without complaint from C.
> ...

If validity as D is not a concern you can also just write:

```c
foo(){ }
```

> The reason is historical, as K+R C did not require a function to 
> annotate its return type, and defaulted to int. K+R C did not have a 
> void type.

Yes, and then `b && foo()` works, even if you don't return a value.


More information about the Digitalmars-d mailing list