开发者

What's the line after execve for since it doesn't return on success?

26: execve(prog[0],prog,env);
27: return 0; 


execve() does not return on success, and  the  text,  data,  bss,  and
       stack  of  the  calling process are overwritten by that of the program
       loaded.

what's return 0;开发者_运维技巧 for?


I suggest it is to cease this compiler warning.

$ cat | gcc -W -Wall -x c -
int main(){}
^D
<stdin>: In function 'main':
<stdin>:1:1: warning: control reaches end of non-void function

This also will make happy static analyzers and IDE warnings about same thing.


That line is in case execve() somehow fails and does return. Theoretically, it never should happen, but it does sometimes. Often, the return value is set to some random number to signify that there was an error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜