헤더 파일에 #include
이 있어야합니까?헤더 파일에 포함
저는 일반적으로 이런 종류의 계층 적 포함이 좋지 않다고 생각합니다. 당신이이 말 :
foo.h :
#include <stdio.h> // we use something from this library here
struct foo { ... } foo;
main.c를
#include "foo.h"
/* use foo for something */
printf(...)
날을 main.c의 구현을 변경, 당신은 더 이상 컴파일 것 foo.h를 사용하지 휴식을 취하고 <stdio.h>
을 직접 추가해야합니다.
이 가진 대 :
foo.h 당신이 foo는을 사용하여 아무것도 중단하지 제거, 그러나 STDIO.H를 제거 중지 할 때
// Warning! we depend on stdio.h
struct foo {...
main.c를
#include <stdio.h> //required for foo.h, also for other stuff
#include "foo.h"
것 foo.h를 깨십시오.
#h 파일에서 #includes를 포함해야합니까?
가능한 복제본 [C++에 대한 표준 #include 규칙이 있습니까?] (http://stackoverflow.com/questions/691079/is-there-a-standard-include-convention-for-c). 이것은 C++가 아니라 C이지만 원칙은 동일합니다. 좋은 충고가 많이 있습니다. http://stackoverflow.com/questions/181921/your-preferred-c-c-header-policy-for-big-projects는 다른 것입니다. –