DataScience
article thumbnail
Published 2024. 2. 7. 10:49
[C] #ifndef~ #endif C++

point.h를 pointOperation.h, main.c 두군데서 포함합니다.

main.c에서는 point.h와 pointOperation.h를 포함합니다.

그러면 point.h는 main.c에서 두번 포함이 됩니다. 

 

중복 포함이 되면 컴파일시 문제가 발생하고 에러메시지를 발생시킵니다.

 

이 문제를 해결하기 위해 매크로 #ifndef ~ #endif를 사용합니다.

#ifndef는 if not defined의 약자로 ~를 정의하지 않았으면 #endif까지 실행해라입니다.

 

모든 헤더 파일에 매크로 #ifndef~ #endif를 사용하는것이 좋습니다.

profile

DataScience

@Ninestar

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!