Make Unreal REAL.
article thumbnail
Published 2023. 2. 21. 22:05
__cplusplus C++/기타

 

__cplusplus 매크로를 이용해 지원하는 C++ 버전에 따라 조건부 컴파일을 수행할 수 있다.

 

int reduce_func(vector<int> S)
{
#if (__cplusplus < 201703L)
    return accumulate(S.begin(), S.end(), 0);
#else
    return reduce(S.begin(), S.end());
#endif
}

 

C++에서는 네임 맹글링을 방지하기 위해 extern "C"를 사용하는데 C 컴파일러에서 이것을 사용하면 컴파일 오류가 발생한다.

 

아래와 같이 처리하여 C++, C 컴파일러 모두에서 사용할 수 있다.

 

#ifdef __cplusplus
extern "C" {
#endif

    /* All C declarations */

#ifdef __cplusplus
}
#endif
profile

Make Unreal REAL.

@diesuki4

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

검색 태그