surprising semantics of the && expression

Timon Gehr timon.gehr at gmx.ch
Thu Feb 5 07:45:51 UTC 2026


On 2/4/26 22:19, Forum User wrote:
> On Wednesday, 4 February 2026 at 09:20:13 UTC, Timon Gehr wrote:
>>
>> Compiles as C as well as D:
>>
>> ```c
>> auto foo(){}
>>
>> void main(){
>>     int b = 1;
>>     b && foo();
>> }
>> ```
> 
> $ gcc -Wall -pedantic -pedantic-errors c.c
> c.c:1:6: error: function definition declared 'auto'
>      1 | auto foo(){}
>        |      ^~~
> c.c:1:6: error: return type defaults to 'int' [-Wimplicit-int]
> c.c:3:6: error: return type of 'main' is not 'int' [-Wmain]
>      3 | void main(){
>        |      ^~~~
> c.c: In function 'main':
> c.c:5:7: warning: value computed is not used [-Wunused-value]
>      5 |     b && foo();
>        |       ^~
> c.c: In function 'foo':
> c.c:1:12: warning: control reaches end of non-void function [-Wreturn-type]
>      1 | auto foo(){}
>        |            ^
> 

gcc -w c.c



More information about the Digitalmars-d mailing list