0

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)

2
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by vedro-compota
1

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

Edited by nezachem: n/a

Votes + Comments
+++++
0

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/

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.