‘__FILE__ ‘, __LINE__’ 이란 무엇인가?

로그 라이브러리를 분석하던 중, __FILE__ 과 __LINE__ 이라는 구문을 발견하고 의문을 가져 내용을 찾아보았다.
아래의 주소에서 내용을 확인할 수 있었다.

http://www.codeguru.com/forum/showthread.php?t=231043

정답은 __FILE__ 과 __LINE__ 은 전처리기(Preprocessor) 에서 지정해주는 매크로라는 것.

__FILE__ 의 경우 현재 __FILE__ macro 를 사용한 파일의 이름을 나타내주고

__LINE__ 의 경우 현재 __LINE__ macro 를 사용한 파일에서 몇 번째 줄에 위치했는지를 나타내준다.

이와 비슷한 전처리기 매크로는

  • ‘__DATE__’ -> a string literal of the form “Mmm dd yyyy”
  • ‘__TIME__’ -> a string literal of the form “hh:mm:ss”
  • ‘__TIMESTAMP__’ -> a string literal of the form “Mmm dd yyyy hh:mm:ss”
  • ‘__FUNCTION__’ -> a string literal which contains the function name (this is part of C99, the new C standard and not all C++ compilers support it)

가 있다.

아래는 __FILE__ 과 __LINE__ 을 이용한 예제와 결과이다.

#include 

int main(int argc, char** argv)
{
        printf("%s:%dn", __FILE__, __LINE__);
        return 0;
}

결과

jonathan@jonathan-laptop:~/Desktop/temp/test$ ./test
test.c:6

1 Comment on What is ‘__FILE__’ and ‘__LINE__’?

  1. 방문자 says:

    좋은 자료 감사합니다.
    아래 주소로 담아갑니다.
    http://blog.naver.com/fochaerim/70126624467
    문제되면 삭제하겠습니다.

Leave a Reply to 방문자 Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.