当前位置: 技术问答>linux和unix
关于UNIX环境高级编程第4章里面的程序4-7
来源: 互联网 发布时间:2015-12-24
本文导语: 我得书是第2版的,第101页中间,dopath函数里面有条语句 if((ret=func(fullpath,&statbuf,FTW_D)!=0) 还有while语句中跳出循环的那句,if((ret=dopath(func))!=0) break; 我想问的是他们所调用的myfunc函数返回值都是0,那么一直都是ret=0了...
我得书是第2版的,第101页中间,dopath函数里面有条语句
if((ret=func(fullpath,&statbuf,FTW_D)!=0)
还有while语句中跳出循环的那句,if((ret=dopath(func))!=0) break;
我想问的是他们所调用的myfunc函数返回值都是0,那么一直都是ret=0了。
so,how can,ret!=0跳出while循环体呢。没有看懂。。。
哪位高手帮忙翻看一下,多谢!!!
if((ret=func(fullpath,&statbuf,FTW_D)!=0)
还有while语句中跳出循环的那句,if((ret=dopath(func))!=0) break;
我想问的是他们所调用的myfunc函数返回值都是0,那么一直都是ret=0了。
so,how can,ret!=0跳出while循环体呢。没有看懂。。。
哪位高手帮忙翻看一下,多谢!!!
|
That's exactly how i understand the program. the "break" will never be executed.
i think the "if((ret=dopath(func))!=0) break;" is for error handling for the case that myfunc() returns non-zero value. but routine myfunc() was not programmed appropriately to fit the error handling.
But why did [W. Richard Stevens] program the routine like that? I can not understand.I think he only wanted the return value checked.
Anywany, it is very good to check the return value of your routine.
Regards
Do not forget to close the topic and give me the 20 Fen ^_^
i think the "if((ret=dopath(func))!=0) break;" is for error handling for the case that myfunc() returns non-zero value. but routine myfunc() was not programmed appropriately to fit the error handling.
But why did [W. Richard Stevens] program the routine like that? I can not understand.I think he only wanted the return value checked.
Anywany, it is very good to check the return value of your routine.
Regards
Do not forget to close the topic and give me the 20 Fen ^_^