首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

如何解决这一个warning

2012-02-06 
怎么解决这一个warning刚学Unix编程,系统是freebsd5.4,编译器是gccV3.4.2,在编译下面程序时总是有warning:

怎么解决这一个warning
刚学Unix编程,系统是freebsd5.4,   编译器是gcc   V3.4.2,在编译下面程序时总是有warning:   assignment   makes   pointer   from   integer   without   a   cast
google和baidu了大半天都没能找到,请高手指点下,怎样才能去掉warning?

出warning的地方加上中文释了

#define   _POSIX_SOURCE   199506L       /*有人说加上这一句可以去掉warning   ,但我加上了也没用*/


#include   "apue.h "
#include   <dirent.h>

#include   <errno.h>   /*for   definition   of   errno*/
#include   <stdarg.h>   /*for   c   variable   arguments*/


#include   <syslog.h>


int   log_to_stderr;

int   main(int   argc,   char   *argv[])
{
          DIR   *dp;
          struct   dirent   *dirp;

          if(argc   !=   2)
                    err_quit( "usage:   ls   directory_name ");
         
          if(dp   =   opendir(argv[1])   ==   NULL)             /*出了warning*/
                    err_sys( "can 't   open   %s ",   argv[1]);

          while(dirp   =   readdir(dp)   !=   NULL)             /*出了warning*/
                    printf( "%s\n ",   dirp   -> d_name);

          closedir(dp);
          exit(0);
}

//#include   "apue.h "


static   void   err_doit(int,   int,   const   char   *,   va_list);

/*
  *   Nonfatal   error   related   to   a   system   call.
  *   Print   a   message   and   return.
  */
void   err_ret(const   char   *fmt,   ...)
{
va_list   ap;

va_start(ap,   fmt);
err_doit(1,   errno,   fmt,   ap);
va_end(ap);
}

/*
  *   Fatal   error   related   to   a   system   call
  *   Print   a   message   and   terminate
  */
void   err_sys(const   char   *fmt,   ...)
{
va_list   ap;

va_start(ap,   fmt);
err_doit(1,   errno,   fmt,   ap);
va_end(ap);
exit(1);
}

/*
  *   Fatal   error   unrelated   to   a   system   call
  *   Error   code   passed   as   explicit   parameter.
  *   Print   error   message   and   terminate.
  */
void   err_exit(int   error,   const   char   *fmt,   ...)
{
va_list   ap;

va_start(ap,   fmt);
err_doit(1,   error,   fmt,   ap);
va_end(ap);
exit(1);
}

/*
  *   Fatal   error   related   to   a   system   call.
  *   Print   a   message,   dump   core,   and   terminate.
  */
void   err_dump(const   char   *fmt,   ...)


{
va_list   ap;

va_start(ap,   fmt);
err_doit(1,   errno,   fmt,   ap);
va_end(ap);
abort();   /*dump   core   and   terminate*/
exit(1);   /*   shouldn 't   get   here*/
}

/*
  *   Nonfatal   error   unrelated   to   a   system   call.
  *   Print   a   message   and   return.
  */
void   err_msg(const   char   *fmt,   ...)
{
va_list   ap;

va_start(ap,   fmt);
  err_doit(0,   0,   fmt,   ap);
va_end(ap);
}

/*  
  *   Fatal   error   unrelated   to   a   system   call.
  *   Print   a   message   and   terminate
  */
void   err_quit(const   char   *fmt,   ...)
{
va_list   ap;

  va_start(ap,   fmt);
err_doit(0,   0,   fmt,   ap);
va_end(ap);
exit(1);
}

/*
  *   Print   a   message   and   return   to   a   caller.
  *   Caller   specifies   "errnoflag ".
  */
static   void   err_doit(int   errnoflag,   int   error,   const   char   *fmt,  
                                          va_list   ap)
{
char   buf[MAXLINE];
vsnprintf(buf,   MAXLINE,   fmt,   ap);
if(errnoflag)
snprintf(buf   +   strlen(buf),   MAXLINE   -strlen(buf),   ":   %s ",
strerror(error));
strcat(buf,   "\n ");
fflush(stdout);     /*in   cast   stdout   and   stderr   are   the   same*/
fputs(buf,   stderr);
fflush(NULL);   /*flushes   all   stdio   output   streams*/
}

/*  
  *   Error   routines   for   programs   that   can   run   as   a   daemon
  */

//#include   "apue.h "


static   void   log_doit(int,   int,   const   char   *,   va_list   ap);

/*
  *   Caller   must   define   and   set   this:   nonzero   if   interactive,
  *   zero   if   daemon
  */
extern   int   log_to_stderr;

/*
  *   Initialize   syslog(),   if   running   as   daemon
  */
void   log_open(const   char   *ident,   int   option,   int   facility)
{
if(log_to_stderr   ==   0)
openlog(ident,   option,   facility);
}

/*
  *   Nonfatal   error   related   to   a   system   call.
  *   Print   a   message   wit   a   system 's   errno   value   and   return.
  */
void   log_ret(const   char   *fmt,   ...)
{
va_list   ap;
va_start(ap,   fmt);
log_doit(1,   LOG_ERR,   fmt,   ap);
va_end(ap);
}

/*
  *   Fatal   error   related   to   a   system   call.
  *   Print   a   message   and   terminate.


  */
void   log_sys(const   char   *fmt,   ...)
{
va_list   ap;
  va_start(ap,   fmt);
log_doit(1,   LOG_ERR,   fmt,   ap);
va_end(ap);
exit(2);
}

/*
  *   Nonfatal   error   unrelated   to   a   system   call.
  *   Print   a   message   and   return
  */
void   log_msg(const   char   *fmt,   ...)
{
va_list   ap;
va_start(ap,   fmt);
log_doit(0,   LOG_ERR,   fmt,   ap);
va_end(ap);
}

/*
  *   Fatal   error   unrelated   to   a   system   call
  *   Print   a   message   and   teminate
  */
void   log_quit(const   char   *fmt,   ...)
{
va_list   ap;
  va_start(ap,   fmt);
log_doit(0,   LOG_ERR,   fmt,   ap);
va_end(ap);
exit(2);
}

/*
  *   Print   a   message   and   return   to   a   caller.
  *   Caller   specifies   "errnoflag "   and   "priority "
  */
static   void   log_doit(int   errnoflag,   int   priority,   const   char   *fmt,
                                            va_list   ap)
{
int   errno_save;
char   buf[MAXLINE];

  errno_save   =   errno;   /*value   caller   might   want   printed*/
vsnprintf(buf,   MAXLINE,   fmt,   ap);
if(errnoflag)
snprintf(buf   +   strlen(buf),   MAXLINE   -   strlen(buf),   ":   %s ",
        strerror(errno_save));
strcat(buf,   "\n ");
if(log_to_stderr){
fflush(stdout);
fputs(buf,   stderr);
fflush(stderr);
}
else{
syslog(priority,   buf);
}
}


[解决办法]
if(dp = opendir(argv[1]) == NULL)
> >
if( (dp = opendir(argv[1])) == NULL)

热点排行