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的第二个参数怎么回事函数指针呢,好奇怪。

阅读 9.1k
2 个回答
✓ 已被采纳新手上路,请多包涵

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

完整的代码是怎样的哦?编译报的错,不是就是说声明的参数类型是个指向函数的指针,但是你传递的是个int类型的实参吗?你把完整代码贴出来看看,我试试。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进