在 Ubuntu 10.04.2 x86_64 上使用 gcc 4.4.3 编译我收到以下警告:
warning: comparison between pointer and integer
对于这一行:
if (strptime(date_time, "%d-%b-%y %T", &tm) == NULL) {
如果我将 NULL 更改为 0,警告就会消失。但是 strptime 的手册页指出它在错误时返回 NULL。我包括<time.h>
在#define __USE_XOPEN 1
上一行。我也试过了#define _XOPEN_SOURCE
。
感谢您的时间。
编辑
完整的包括:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#define __USE_XOPEN 1 /* needed for strptime */
#include <time.h>
#include <arpa/inet.h>
#include <errno.h>
#include "recv.h"
#include "tcp.h"
#include "types.h"
编辑
以下代码给出了相同的警告:
#define __USE_XOPEN 1 /* needed for strptime */
#include <time.h>
#include <stdio.h>
int main()
{
struct tm tm;
char date_time[] = "3-May-11 12:49:00";
if (strptime(date_time, "%d-%b-%y %T", &tm) == NULL) {
fprintf(stderr, "Error: strptime failed matching input\n");
}
return 0;
}
编辑编辑
但是将其更改为 _XOPEN_SOURCE 有效!并将定义移动到程序顶部修复了原始文件。