[C, C++] 함수 앞에 붙는 언더바 (_) 의 의미

Coding · Posted on January 4, 2015 at 05:19 PM

ISO/IEC 14882 에서 정의한 C++ Standard (2003)에 이에 대한 설명이 나와 있습니다.

17.4.3.1.2 Global names [lib.global.names] Certain sets of names and function signatures are always reserved to the implementation: – Each name that contains a double underscore (__) or begins with an underscore followed by an upper-case letter (2.11) is reserved to the implementation for any use. – Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

간단히 해석하자면,

특정한 이름들이나 함수들의 시그니쳐들은 항상 구현을 위해 reserve 되어있다. – 언더스코어 () 가 두번 붙거나 언더스코어 이후에 대문자가 나오는 경우에는 어떤 구현을 위해 reserve 해놓은 것. – 언더스코어 () 로 시작하는 경우에는 글로벌 네임스페이스에 존재하는 이름으로 사용하기 위해 구현해 놓은것.

이건 그냥 표준(Standard)이고 관습(Convention)일 뿐이지, 사실 크게 신경쓰실 필요는 없습니다. 그냥 껍데기 함수 놓고 내부적으로 함수를 implementation(구현) 하기 위해 편의상 그렇게 했다고 생각하시면 되겠습니다. 굳이 필요할 때를 생각하자면 가끔 Unicode 와 ANSI 함수를 나눌 때도 있고 하니..

References

International Organization for Standardization, ISO International Standard ISO/IEC 14882 – Programming Languages C++, Geneva: American National Standards Institute, 2003.

Posted by chlee

0 Comments

Post a comment

Security Code