gpt4 book ai didi

c - 函数指针中的 gcc 警告(不兼容的指针类型)

转载 作者:太空宇宙 更新时间:2023-11-04 01:42:23 27 4
gpt4 key购买 nike

我需要有关 gcc 警告的帮助,看起来我在这里做错了什么

unsigned long convert_syslog(char *date,int year) {
char withyear[1024];
struct tm tm;
time_t epoch = (time_t) NULL;

snprintf(withyear,sizeof(withyear),"%s %i",date,year);
if(strptime(withyear,"%b %d %H:%M:%S %Y",&tm)) {
epoch = mktime(&tm);
printf("%u\n",epoch);
}
return epoch;
}

unsigned long convert_tai64(char *date,int year) {
char hex[16];
unsigned long u;
strcpy(hex,"0x");
strcat(hex,strndup(date+8,8));
return strtoul (hex,NULL,16);
}

unsigned long convert_nagios(char *date,int year) {
return strtoul(date,NULL,10);
}

unsigned long convert_clf(char *date,int year) {
struct tm tm;
time_t epoch = (time_t)NULL;

if(strptime(date,"%d/%b/%Y:%H:%M:%S",&tm)) {
epoch = mktime(&tm);
}
return epoch;
}




typedef unsigned long (*func)(char *data,int year);

func *convert_date(int pos) {
switch(pos) {
case 0: return &convert_syslog;
case 1: return &convert_tai64;
case 2: return &convert_clf;
case 3: return &convert_nagios;
default: return NULL;
}
}

在 convert_date 中给我警告

pcre_search.c:57: warning: return from incompatible pointer type  (case 0)  
pcre_search.c:58: warning: return from incompatible pointer type (...)
pcre_search.c:59: warning: return from incompatible pointer type (...)
pcre_search.c:60: warning: return from incompatible pointer type (default)

最佳答案

您应该返回 func 而不是 func*

关于c - 函数指针中的 gcc 警告(不兼容的指针类型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3139872/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com