Chinaunix首页 | 论坛 | 博客
  • 博客访问: 18422
  • 博文数量: 12
  • 博客积分: 266
  • 博客等级: 二等列兵
  • 技术积分: 110
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-07 10:14
文章分类

全部博文(12)

文章存档

2012年(4)

2011年(8)

我的朋友

分类: C/C++

2011-05-12 19:37:53

Typically   the   return   value   is   used   as   a   exit   status   code   (I   prefer   to   use   the   exit   ()   function   myself).   So   that,   if   your   program   is   called   by   another   program   or   a   shell/batch   script,   the   calling   entity   can   react   to   the   exit   status   appropriately.

To   explain   this   a   little   more   clearly,   assume   your   program   parses   a   large   file   and   inserts   the   parsed   data   into   a   database.   Your   program   is   called   by   a   user   clicking   a   button   in   some   other   program.   How   does   the   user   know   if   your   program   successfully   completed   the   task?   Or,   if   it   was   not   completed   successfully,   why?  

The   easiest   way   to   tell   what   happened   after   your   program   has   completed   is   to   check   the   returned   exit   status   code.   Most   of   the   time   these   codes   are   defined   by   you.   For   instance,   0   if   it   completed   okay,   1   if   it   could   not   connect   to   the   database,   2   if   it   deadlocked   with   another   user   in   the   database,   3   if   it   couldn 't   find   the   file   to   parse,   etc.   Then,   using   these   codes,   the   calling   program   can   print   the   appropriate   message   to   the   user 's   screen,   or   use   some   sort   of   logic   that   will   attempt   to   get   your   program   to   complete   successfully.
阅读(551) | 评论(0) | 转发(0) |
0

上一篇:什么是 socket?

下一篇:UNIX,Linux与FreeBSD

给主人留下些什么吧!~~