2010-06-29 5 views
1

je besoin d'aide avec l'avertissement de gcc, ressemble im quelque chose de mal iciavertissement de gcc pointeur à la fonction (type pointeur incompatible)

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; 
    } 
} 

me donne des avertissements dans 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) 

Répondre

3

Vous devez retourner func pas func*.

1

Func typedef est déjà un pointeur vers une fonction si convert_date peut être déclarée comme ceci:

func convert_date(int pos) { ... 

noms de fonction (en C) sont des pointeurs déjà donc pas besoin de l'& dans les déclarations de retour. Faites simplement ceci:

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 (func)NULL; 
     } 
    } 
Questions connexes