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>
前の行にwithを含めて#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 に変更するとうまくいきました! そして、定義をプログラムの先頭に移動すると、元が修正されました。