Compiler gets warnings when using strptime function (C)

一世执手 提交于 2019-12-10 03:18:58

问题


Typing man strptime it sais that this function needs to have declared _XOPEN_SOURCE and included time.h header. I did it. But, when I try to compile my code I get:

./check.c:56: warning: implicit declaration of function ‘strptime’

Look at my code:

int lockExpired(const char *date, const char *format, time_t current) {
        struct tm *tmp = malloc(sizeof(struct tm *));
        time_t lt;
        int et;

        strptime(date, format, tmp);
        lt = mktime(tmp);
        et = difftime(current, lt);

        if (et < 3600)
                return -et;

        return 1;
}

Also the function declaration is:

char *strptime(const char *s, const char *format, struct tm *tm);

Can anyone tell me where my problem come from?


回答1:


I've found that I needed to define __USE_XOPEN and also _GNU_SOURCE to get it to be happy.



来源:https://stackoverflow.com/questions/15334558/compiler-gets-warnings-when-using-strptime-function-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!