Altruistic Programmer's Blog (KR)

이타주의 프로그래머의 블로그

C++ 현재 함수이름 얻기

with one comment

[옛날 블로그 글입니다. 2009.05.16]

C에는 현재 함수의 이름을 알려주는 __func__라는 식별자가 미리 정의되어 있었네요. (C99) C++는 컴파일러마다 조금씩 다른데,  MSVC는 __FUNCTION__이네요. 아래처럼하면 wchar_t* 버전도 쉽게 만들 수 있습니다. (yvals.h)

#define _STR2WSTR(str)    L##str
#define STR2WSTR( str ) _STR2WSTR( str )
#define __FUNCTIONW__  STR2WSTR(__FUNCTION__)

MSDN보면 데코레이션된 이름을 반환하는 매크로나, 시그니처를 반환하는 매크로도 있네요. (__FUNCDNAME__, __FUNCSIG__)
http://msdn.microsoft.com/en-us/library/b0084kay.aspx

boost의 current_function.hpp를 보시면, 컴파일러별로 죄다 정의해둔 것도 있네요.
http://www.boost.org/doc/libs/1_38_0/boost/current_function.hpp

Written by muscly

May 16th, 2009 at 12:36 pm

One Response to 'C++ 현재 함수이름 얻기'

Subscribe to comments with RSS or TrackBack to 'C++ 현재 함수이름 얻기'.

  1. 헉.. 이런게 있었다니?

    16 Jun 09 at 6:38 am

Leave a Reply