因此,函数getdate_r
对我来说似乎没有定义;编译以下内容在gcc或clang中都不起作用,(手册页程序也不起作用)
#include <time.h>
int main() {
char timeString[] = "2015/01/01 10:30:50";
struct tm res = {0};
int err = getdate_r(timeString, &res);
return err;
}
clang报告如下
test.c:6:12: warning: implicit declaration of function 'getdate_r' is invalid
in C99 [-Wimplicit-function-declaration]
int err = getdate_r(timeString, &res);
^
1 warning generated.
time.h
的其他函数,如getdate
、strptime
,也不以类似的方式工作。
有人能解释一下发生了什么事吗?
clang版本信息
Ubuntu clang version 3.6.0-2ubuntu1 (tags/RELEASE_360/final) (based on LLVM 3.6.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
发布于 2015-09-01 04:23:46
要使getdate_r
可用,您需要:
#define _GNU_SOURCE 1
在包含任何包含文件之前。这样做将为各种GNU扩展(包括getdate_r
)提供声明。
#define _GNU_SOURCE 1
#include <time.h>
int main(void) {
char timeString[] = "2015/01/01 10:30:50";
struct tm res = {0};
int err = getdate_r(timeString, &res);
return err;
}
https://stackoverflow.com/questions/32331269
复制