Cualquier razón específica por la que Localtime lanza advertencia con Struct TM * & Stat *, en Linux?
Pregunta
Tengo este código simple (parte de un proyecto):
void displayFileProperties(struct stat* file,char* outputProperties , char * path)
{
struct tm* time;
// code
// code
time = localtime(&file->st_mtim);
// code
}
donde Eclipse me sigue lanzándome una advertencia:
passing argument 1 of ‘localtime’ from incompatible pointer type [enabled by default] main.c /ex4 line 340 C/C++ Problem
¿Alguna idea de cómo solucionar esto?gracias
Solución
st_mtim
es un Tiempo de estructura (segundos y nanosegundos).Quieres st_mtime
.
Otros consejos
Querrás usar esto en su lugar:
time = localtime(&file->st_mtime);
Nota el 'E' agregado al final.st_mtim es un TimesPec, con 'E' agregó que es un tiempo_t (lo que necesita).
Respuesta completamente cambiada:
Sugerencias:
1) Asegúrese de que #inClude estos encabezados:
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
2) Etrice su puntero a "Const"
time = localtime((const time_t *)&file->st_mtime);
3) Publique lo que sucede
=====================================================
Sugerencias adicionales:
1) Lea estos dos enlaces:
C stat stat struct no tiene un campo ST_CTITE, sino solo st_ctim
http:/linux.die.net/man/2/lstat < / a>
2) Claramente, el makefile (que "funciona") tiene una #define que Eclipse no, o viceversa.
probablemente cualquiera / ambos _posix_c_source y / o _xopen_source.
Ejecute este comando para ver lo que existe en la línea de comandos (Makefile?) Entorno:
Tuve el mismo problema con Eclipse: El campo St_mtime no se pudo resolver (error semántico)
Se solucionó el problema en Eclipse haciendo clic con el botón derecho en el proyecto, elija Índice -> "Refrescar todos los archivos"
#include <malloc.h>
#include <time.h>
#include <stdio.h>
static struct tm* alarmTime(void);
int main(){
printf("Hour :%i\n", alarmTime()->tm_hour);
printf("Minute :%i\n", alarmTime()->tm_min);
return 0;
}
static struct tm* alarmTime(void){
time_t now = time(NULL);
struct tm* ptm;
#ifdef HAVE_LOCALTIME_R
struct tm tmbuf;
ptm = localtime_r(&now, &tmbuf);
#else
ptm = localtime(&now);
#endif
return ptm;
}