C언어

c언어 #ifndef #endif headerfile

거부 2021. 8. 3. 18:59

[코드]

헤더파일 level5-2.h가 있으면

#ifndef __level5_2_h__

#endif

 

[설명]

헤더파일의 중복을 막기 위해 사용하는 문법이다.

#ifndef 넣고 __헤더파일명__ 으로 언더바를 두번씩 내려준 후 #endif로 마무리하면된다.

이때 모든 특수문자는 _로 처리해주고 문자, 숫자는 그대로 작성해준다.

 

[연습해보자]

헤더파일 eng.h

헤더파일2 eng2.h

헤더파일3 eng3-3.h

 

각각

#ifndef __eng_h__

#ifndef __eng2_h__

#ifndef __eng3_3_h__

로 쓴후

#endif 각각 닫아주면 끝난다

 

화이팅~