Skip to content

Instantly share code, notes, and snippets.

@brimston3
Created September 12, 2017 14:34
Show Gist options
  • Save brimston3/2be168bb423c83b0f469c0be56e66d31 to your computer and use it in GitHub Desktop.
Save brimston3/2be168bb423c83b0f469c0be56e66d31 to your computer and use it in GitHub Desktop.
use preprocessor to detect C++ RTTI flags
/*
* 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;
}
@mattfbacon
Copy link

Probably should be __GNUC__, not __GNUG__.

@brimston3
Copy link
Author

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