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

All 4 Replies

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

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/

thanks! it's sloved know)

Be a part of the DaniWeb community

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