14 May 2010

Strangers in C

While looking in some books, I found a C code with this meaning:

#include <stdio.h>

int connect_to_server();

int main(void){
connect_to_server() && printf("Connection successed\n");
return 0;
}

int connect_to_server(){
// do connection staff here
// if connection successed
return 1;
}



Actually, It is very similar to bash script!

3 comments:

mohamed yosry said...

I'm finally get ur blog :D

this type of statement depend on compiler optimization , if first statement with operator (&&) doesn't succeed (evaluated to 1 (true) the following statement will ignore ( not evaluated ) otherwise it evaluates (print in this example) .

i think it should work in java (same evaluation principles )

mohamed yosry said...

another one

return x > y ? (x>z?1:0):0 ;

u haven't to know all of them , but when u get one of them be sure it have logical flaw cuz c have known rules (besides compilers extensions )

mhewedy said...

thanks for your comments :)