はじめてC言語 .hファイルの意味を理解した!
cのヘッダーファイルの意味
http://www.geocities.jp/ky_webid/ProgrammingPlacePlus/c/023.html
ポイントは,
各ファイルで関数宣言をしないと関数を使用できない
→これが.hファイル
実態は,.cファイルで定義する.
extern は他のところで定義されたグローバル変数にアクセスする場合に用いる
static はそのファイルからアクセスできないようにする
extern は .h にかいておくといい。
例2:
test_hello.h
#ifndef test_hello #define test_hello #ifdef _cplusplus extern "C" { #endif void test1(char* v); void test2(); #ifdef _cplusplus } #endif #endif
#ifdef _cplusplus
#endif
はc++ のときにif endif内のコードを実行するという意味
extern "C" はC言語の関数を表す