surprising semantics of the && expression

Forum User forumuser at example.com
Wed Feb 4 21:19:33 UTC 2026


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(){}
       |            ^



More information about the Digitalmars-d mailing list