Previous: Standard Symbols, Up: Common Behavior
ヘッダファイルの設定に依存するテストもあります.これらのヘッダは例外無く 利用可能というわけではないので,テストは,以下のようなインクルードを保護 する(コードの)組を,実際に提供する必要があります.
#if TIME_WITH_SYS_TIME # include <sys/time.h> # include <time.h> #else # if HAVE_SYS_TIME_H # include <sys/time.h> # else # include <time.h> # endif #endif
どうすれば良いか正確に知らない場合,無条件のインクルードの使用は避け,イ ンクルードする前にヘッダの存在を調査すべきです(see Header Files).
最も一般的なマクロは,以下のようなインクルードのデフォルトの組を提供する マクロを使用しています.
include-directivesが定義されている場合はそれを展開し,そうでなけれ ば以下のようになります.
#include <stdio.h> #if HAVE_SYS_TYPES_H # include <sys/types.h> #endif #if HAVE_SYS_STAT_H # include <sys/stat.h> #endif #if STDC_HEADERS # include <stdlib.h> # include <stddef.h> #else # if HAVE_STDLIB_H # include <stdlib.h> # endif #endif #if HAVE_STRING_H # if !STDC_HEADERS && HAVE_MEMORY_H # include <memory.h> # endif # include <string.h> #endif #if HAVE_STRINGS_H # include <strings.h> #endif #if HAVE_INTTYPES_H # include <inttypes.h> #else # if HAVE_STDINT_H # include <stdint.h> # endif #endif #if HAVE_UNISTD_H # include <unistd.h> #endifデフォルトのインクルードが使用される場合,これらのヘッダの存在とその互換 性を調査します.すなわち,
AC_HEADERS_STDC
を実行する必要も, stdlib.hなどを調査する必要もありません.これらのヘッダは,インクルードされる順番と同じ順番で調査されます.例えば, string.hとstrings.hの両方があるシステムもありますが,競合 しません.そこでは,
HAVE_STRING_H
は定義されますが,HAVE_STRINGS_H
は定義されません.