私は学んC
でいて、ファイルをどこに含めるべきかわからない。基本的に、これはファイル内.c
または.h
ファイル内で実行できます。
オプション1
test.h
int my_func(char **var);
test.c
#include <stdio.h>
#include "test.h"
int my_func(char **var) {printf("%s\n", "foo");}
int main() {...}
オプション2
test.h
#include <stdio.h>
int my_func(char **var);
test.c
#include "test.h"
int my_func(char **var) {printf("%s\n", "foo");}
int main() {...}
オプション2を使用すると、ライブラリが必要test.h
な.c
ファイルに含めるだけで済みます。私が見る例のほとんどはオプション1を使用しています。
いつ何をするかという一般的なルールはありますか、それとも個人的な好みの問題ですか?