syslog - expected ‘int * (*)()’ but argument is of type ‘int’ 错误

查看:179
本文介绍了syslog - expected ‘int * (*)()’ but argument is of type ‘int’ 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

今天写了个log函数,如下(定义在logger.c中, logger.h中有对应的声明)

    void Logger(int priority, int errno, char* fmt, ...)
    {
        char priVc[][8] = {"Emerg", "Alert", "Crit", "Error", "Warning", "Notice", "Info", "Debug"};
    
        char* priPt = priority < 0 || priority >= sizeof(priVc)/sizeof(priVc[0]) ?
            "Unknow priority!" : priVc[priority];
    
        char *errMsg = errno <= 0 ? NULL : strerror(errno);
    
        {
            va_list argPt;
            unsigned Ln;
    
            va_start(argPt, fmt);  //now argPt is point to mylog's param:...
            Ln = snprintf(LogLastMsg, sizeof(LogLastMsg), "[mylog...][%s]: ", priPt);
            Ln += vsnprintf(LogLastMsg + Ln, sizeof(LogLastMsg) - Ln, fmt, argPt);
            if (NULL != errMsg)
            {
                Ln += snprintf(LogLastMsg + Ln, sizeof(LogLastMsg) - Ln, "%d:%s", errno, errMsg);
            }
            va_end(argPt);
        }
        //choose the log which should be show on stderr
        if (priority < LOG_ERR || priority <= Log2Stderr)
        {
            fprintf(stderr, "%s", LogLastMsg);
        }
    
        //always to syslog
        syslog(priority, "%s", LogLastMsg);
    
        if (priority <= LOG_ERR)
        {
            exit(-1);
        }
        return ;
    }

然后在main函数中调用:

Logger(LOG_INFO, 3, "httpd start...\n"); 

接着就报错了

 expected ‘int * (*)()’ but argument is of type ‘int’

把logger.c logger.h 以及main.c中调用的Logger都替换成my_log,也没有用。
int *(*)()应该是函数指针把,Logger的第二个参数怎么回事函数指针呢,好奇怪。

解决方案

找到原因了。
errno 在errno.h中被定义成宏了。 不能做形式参数,否则会被变成int )型

这篇关于syslog - expected ‘int * (*)()’ but argument is of type ‘int’ 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆