Files

160 lines
4.8 KiB
C++

/**
* @file include/ActivMiddleware/Config/Compilers/GCC.h
*
* @brief GNU C++ configuration file.
*/
#if (!defined ACTIV_CONFIG_COMPILERS_GCC_H)
#define ACTIV_CONFIG_COMPILERS_GCC_H
#if (ACTIV_GCC_COMPILER_VERSION < ACTIV_MAKE_GCC_COMPILER_VERSION(4, 0))
#error GCC version not supported
#endif
#if (!defined ACTIV_COMPILER_NAME)
#define ACTIV_COMPILER_NAME "GNU C++ " __VERSION__
#endif
#if (!defined ACTIV_PLATFORM_WINDOWS)
#define ACTIV_BUILDING_DLL_EXPORTED_API __attribute__ ((visibility("default")))
#define ACTIV_BUILDING_DLL_INLINE_API __attribute__ ((visibility("hidden")))
#define ACTIV_BUILDING_DLL_LOCAL_API __attribute__ ((visibility("hidden")))
#define ACTIV_USING_DLL_EXPORTED_API
#define ACTIV_USING_DLL_INLINE_API
#define ACTIV_USING_DLL_LOCAL_API
#else
#define ACTIV_BUILDING_DLL_EXPORTED_API
#define ACTIV_BUILDING_DLL_INLINE_API
#define ACTIV_BUILDING_DLL_LOCAL_API
#define ACTIV_USING_DLL_EXPORTED_API
#define ACTIV_USING_DLL_INLINE_API
#define ACTIV_USING_DLL_LOCAL_API
#endif
#define ACTIV_BUILDING_LIB_EXPORTED_API
#define ACTIV_BUILDING_LIB_INLINE_API
#define ACTIV_BUILDING_LIB_LOCAL_API
#define ACTIV_USING_LIB_EXPORTED_API
#define ACTIV_USING_LIB_INLINE_API
#define ACTIV_USING_LIB_LOCAL_API
/**
* @brief Declare an "uninitialized" variable such that it does not create a compilation warning.
*
* Certain compilers (e.g. gcc 3.4) are not "intelligent" enough to figure out that an uninitialized variable
* will be initialized before use in all code paths. Use this macro to declare and initialize such a variable
* with a dummy value to bypass such warnings. With compilers that do not suffer from this problem, this macro
* just declares the variable uninitialized.
*/
#if (ACTIV_GCC_COMPILER_VERSION >= ACTIV_MAKE_GCC_COMPILER_VERSION(4, 1))
#define ACTIV_DECLARE_UNINITIALIZED_VARIABLE(type, name, dummyValue) type name
#else
#define ACTIV_DECLARE_UNINITIALIZED_VARIABLE(type, name, dummyValue) type name = dummyValue
#endif
/**
* @brief Define rules for exporting template member functions.
*
* The Intel & Visual C++ compilers have different rules for __declspec exporting template
* instantiations from dlls. Use ACTIV_TEMPLATE_API as a workaround, e.g.
*
* class Example
* {
* template \<typename T\>
* ACTIV_TEMPLATE_API(MY_LIB_API) void Fn(T &);
* };
*
* @param a __declspec macro, e.g. ACTIV_BASE_API.
*/
#define ACTIV_TEMPLATE_API(a) a
#if (!defined ACTIV_DECLARE_TEMPLATE_PARAMETER_FRIEND)
#if (ACTIV_GCC_COMPILER_VERSION >= ACTIV_MAKE_GCC_COMPILER_VERSION(4, 7))
#define ACTIV_DECLARE_TEMPLATE_PARAMETER_FRIEND(T) friend T
#else
namespace Activ
{
template<typename T>
class GccFriendWorkaround
{
public:
typedef T type;
};
} // namespace Activ
#define ACTIV_DECLARE_TEMPLATE_PARAMETER_FRIEND(T) friend class ::Activ::GccFriendWorkaround<T>::type
#endif
#endif
//! Ensure a function is always inlined.
#if (defined _DEBUG)
#define ACTIV_FORCE_INLINE inline
#else
#define ACTIV_FORCE_INLINE inline __attribute__((__always_inline__))
#endif
//! Ensure a function is never inlined.
#define ACTIV_NEVER_INLINE __attribute__((__noinline__))
/**
* @brief Specify that a function is a printf style function.
*
* @param type printf, scanf, strftime.
* @param formatIndex for static or global functions, the 1-based index of the parameter containing the format specifier string.
* For member functions, the 2-based index.
* @param firstParameterIndex for static or global functions, the 1-based index of the parameter containing the first value to be
* used by the format string. For member functions, the 2-based index.
* Use 0 if the function takes a va_list of parameters.
*/
#define ACTIV_PRINTF_FUNCTION(type, formatIndex, firstParameterIndex) \
__attribute__ ((format (type, formatIndex, firstParameterIndex)))
#define stricmp strcasecmp
#define strnicmp strncasecmp
/**
* @brief Give a hint that a switch case statement is likely.
*
* Usage:
* switch (ACTIV_LIKELY_SWITCH_CASE(variable, 0))
* {
* case 0: <-- the expected case.
* case 1:
* ...
* default:
* }
*
* If the expected case statement is not present then default is the likely case.
*
* @param expr the expression under test.
* @param expected the expected value of expr.
*
* @return expr
*/
#define ACTIV_LIKELY_SWITCH_CASE(expr, expected) __builtin_expect(expr, expected)
/**
* @brief Give a hint that an expression is @a likely to be true.
*
* @param expr
*/
#define ACTIV_LIKELY(expr) __builtin_expect(!!(expr), 1)
/**
* @brief Give a hint that an expression is @a unlikely to be true.
*
* @param expr
*/
#define ACTIV_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
// TODO: add _DEBUG case counting mispredicted cases.
//! Mark a function with the hot attribute.
#define ACTIV_HOT __attribute__ ((hot))
//! Mark a function with the cold attribute.
#define ACTIV_COLD __attribute__ ((cold))
#endif // (!defined ACTIV_CONFIG_COMPILERS_GCC_H)