Created
September 12, 2017 14:34
-
-
Save brimston3/2be168bb423c83b0f469c0be56e66d31 to your computer and use it in GitHub Desktop.
use preprocessor to detect C++ RTTI flags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* g++ has_rtti.cpp -o has_rtti && ./has_rtti | |
* g++ -fno-rtti has_rtti.cpp -o has_rtti && ./has_rtti | |
* clang++ has_rtti.cpp -o has_rtti && ./has_rtti | |
* clang++ -fno-rtti has_rtti.cpp -o has_rtti && ./has_rtti | |
* @TODO: add msc++ cli, /GR, /GR- | |
* | |
* Copyright 2017, Andrew Domaszek | |
* All rights reserved. | |
* Program made available under BSD-new license. | |
*/ | |
#include <stdio.h> | |
#if defined(__clang__) | |
#if __has_feature(cxx_rtti) | |
#define RTTI_ENABLED | |
#endif | |
#elif defined(__GNUG__) | |
#if defined(__GXX_RTTI) | |
#define RTTI_ENABLED | |
#endif | |
#elif defined(_MSC_VER) | |
#if defined(_CPPRTTI) | |
#define RTTI_ENABLED | |
#endif | |
#endif | |
int main() | |
{ | |
#if defined(RTTI_ENABLED) | |
printf("rtti enabled and detected\n"); | |
#else | |
printf("rtti not detected\n"); | |
#endif | |
return 0; | |
} |
I guess I could, but why is someone compiling C++ with the gcc frontend?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably should be
__GNUC__
, not__GNUG__
.