time.h什么时候不包含getdate和strptime?
When is getdate and strptime not included in time.h?
所以函数 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
要使 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;
}
所以函数 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
要使 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;
}