Hi ,programmers!
Please tell me why it's possible to use such condition -

[U]if (!fork ( ))[/U] return 1;

as I know the fork() returns pid_t-type but at the same time "if" needs boolean..

big thanks in advance)

Recommended Answers

There's no boolean in C. Any incarnation of zero resolves to false; everything else resolves to true. [ICODE]!fork()[/ICODE] is therefore synonymous to [ICODE]fork() == 0[/ICODE]

Jump to Post

All 4 Replies

Re: "if (!fork ( ))" condition 80 80

There's no boolean in C. Any incarnation of zero resolves to false; everything else resolves to true. !fork() is therefore synonymous to fork() == 0

commented: +++++ +3
Re: "if (!fork ( ))" condition 80 80

thank you , nezachem)

Re: "if (!fork ( ))" condition 80 80

but what about this piece of code -

ret = stat (argv[1], &sb); 

    if (ret) 
    {
        perror ("stat");
        return 1;
    }

as I understand - the "ret" will be =0 after successful perfomance of "stat", but this code won't return an error ...why is it so? explain please/

Re: "if (!fork ( ))" condition 80 80

thanks! it's sloved know)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.