XSFoundation macros
Function name
#ifndef __func__
#ifdef _WIN32
#if defined( __FUNCTION__ )
#define __func__ __FUNCTION__
#else
#if defined( __FUNCSIG__ )
#define __func__ __FUNCSIG__
#else
#if defined( __FUNCDNAME__ )
#define __func__ __FUNCDNAME__
#else
#define __func__ "<unknown function>"
#endif
#endif
#endif
#else
#if __STDC_VERSION__ < 199901L
#ifdef __GNUC__
#if __GNUC__ >= 2
#define __func__ __FUNCTION__
#else
#define __func__ "<unknown function>"
#endif
#else
#define __func__ "<unknown function>"
#endif
#endif
#endif
#endif
Gets an absolute value of a value
#if !defined( __STRICT_ANSI__ ) && ( defined( __GNUC__ ) || defined( __clang__ ) )
#define XS_ABS( _a_ ) ( \
{ \
__typeof__( _a_ ) __a = ( _a_ ); \
( __a < 0 ) ? -__a : __a; \
} )
#else
#define XS_ABS( _a_ ) ( ( ( _a_ ) < 0 ) ? ( -( _a_ ) ) : ( _a_ ) )
#endif
The absolute value of the value
Standardization of the const compiler attribute
#if defined( __GNUC__ ) && ( ( __GNUC__ >= 4 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) )
#define XS_CONST_ATTRIBUTE __attribute__( ( const ) )
#else
#define XS_CONST_ATTRIBUTE
#endif
Not all compiler support this attribute, so it may be defined to nothing.
Standardization of the deprecated compiler attribute
#if defined( __GNUC__ ) && ( ( __GNUC__ >= 4 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) )
#define XS_DEPRECATED_ATTRIBUTE __attribute__( ( deprecated ) )
#else
#define XS_DEPRECATED_ATTRIBUTE
#endif
Not all compiler support this attribute, so it may be defined to nothing.
Standardization of the extern keyword for exported symbols
#if defined( __WIN32__ )
#define XS_EXPORT XS_EXTERN __declspec( dllimport )
#else
#define XS_EXPORT XS_EXTERN
#endif
Standardization of the extern keyword
#if defined( __cplusplus )
#define XS_EXTERN extern "C"
#else
#define XS_EXTERN extern
#endif
Substitution for 'extern "C" {' start, when compiling with C++
#ifdef __cplusplus
#define XS_EXTERN_C_BEGIN extern "C" {
#else
#define XS_EXTERN_C_BEGIN
#endif
Substitution for 'extern "C" {' end, when compiling with C++
#ifdef __cplusplus
#define XS_EXTERN_C_END }
#else
#define XS_EXTERN_C_END
#endif
Standardization of the format compiler attribute
#if defined( __GNUC__ ) && ( ( __GNUC__ >= 4 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) )
#define XS_FORMAT_ATTRIBUTE( f, s, v ) __attribute__( ( format( f, s, v ) ) )
#else
#define XS_FORMAT_ATTRIBUTE( f, s, v )
#endif
Not all compiler support this attribute, so it may be defined to nothing.
Standardization of the inline compiler keyword
#if defined( __GNUC__ ) && ( __GNUC__ == 4 ) && !defined( DEBUG )
#define XS_INLINE static __inline__ __attribute__( ( always_inline ) )
#else
#if defined( __GNUC__ )
#define XS_INLINE static __inline__
#else
#if defined( __MWERKS__ ) || defined( __cplusplus )
#define XS_INLINE static inline
#else
#if defined( _MSC_VER )
#define XS_INLINE static __inline
#else
#define XS_INLINE
#endif
#endif
#endif
#endif
Gets the maximum value of two values
#if !defined( __STRICT_ANSI__ ) && ( defined( __GNUC__ ) || defined( __clang__ ) )
#define XS_MAX( _a_, _b_ ) ( \
{ \
__typeof__( _a_ ) __a; \
__typeof__( _b_ ) __b; \
__a = ( _a_ ); \
__b = ( _b_ ); \
( __a < __b ) ? __b : __a; \
} )
#else
#define XS_MAX( _a_, _b_ ) ( ( ( _a_ ) > ( _b_ ) ) ? ( _a_ ) : ( _b_ ) )
#endif
The maximum value of the two values
Gets the minimum value of two values
#if !defined( __STRICT_ANSI__ ) && ( defined( __GNUC__ ) || defined( __clang__ ) )
#define XS_MIN( _a_, _b_ ) ( \
{ \
__typeof__( _a_ ) __a; \
__typeof__( _b_ ) __b; \
__a = ( _a_ ); \
__b = ( _b_ ); \
( __a < __b ) ? __a : __b; \
} )
#else
#define XS_MIN( _a_, _b_ ) ( ( ( _a_ ) < ( _b_ ) ) ? ( _a_ ) : ( _b_ ) )
#endif
The minimum value of the two values
Standardization of the noreturn compiler attribute
#if defined( __GNUC__ ) && ( ( __GNUC__ >= 4 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) )
#define XS_NORETURN_ATTRIBUTE __attribute__( ( noreturn ) )
#else
#define XS_NORETURN_ATTRIBUTE
#endif
Not all compiler support this attribute, so it may be defined to nothing.
Maximum length for a path
#if defined( _WIN32 )
#define XS_PATH_MAX MAX_PATH
#else
#define XS_PATH_MAX PATH_MAX
#endif
The separator character used in paths
#if defined( _WIN32 )
#define XS_PATH_SEPARATOR '\\'
#else
#define XS_PATH_SEPARATOR '/'
#endif
Swap endiannes of a 16 bits value
#define XS_SWAP_16( _value_ ) ( ( ( ( uint16_t )( _value_ ) >> 8 ) & 0x00FF ) | ( ( ( uint16_t )( _value_ ) << 8 ) & 0xFF00 ) )
Swap endiannes of a 32 bits value
#define XS_SWAP_32( _value_ ) ( ( ( ( uint32_t )( _value_ ) >> 24 ) & 0x000000FF ) | ( ( ( uint32_t )( _value_ ) >> 8 ) & 0x0000FF00 ) | ( ( ( uint32_t )( _value_ ) << 8 ) & 0x00FF0000 ) | ( ( ( uint32_t )( _value_ ) << 24 ) & 0xFF000000 ) )
Swap endiannes of a 64 bits value
#define XS_SWAP_64( _value_ ) ( ( ( ( uint64_t )( _value_ ) >> 56 ) & 0x00000000000000FFULL ) | ( ( ( uint64_t )( _value_ ) >> 40 ) & 0x000000000000FF00ULL ) | ( ( ( uint64_t )( _value_ ) >> 24 ) & 0x0000000000FF0000ULL ) | ( ( ( uint64_t )( _value_ ) >> 8 ) & 0x00000000FF000000ULL ) | ( ( ( uint64_t )( _value_ ) << 8 ) & 0x000000FF00000000ULL ) | ( ( ( uint64_t )( _value_ ) << 24 ) & 0x0000FF0000000000ULL ) | ( ( ( uint64_t )( _value_ ) << 40 ) & 0x00FF000000000000ULL ) | ( ( ( uint64_t )( _value_ ) << 56 ) & 0xFF00000000000000ULL ) )
Standardization of the unavailable compiler attribute
#if defined( __GNUC__ ) && ( ( __GNUC__ >= 4 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) )
#define XS_UNAVAILABLE_ATTRIBUTE __attribute__( ( unavailable ) )
#else
#define XS_UNAVAILABLE_ATTRIBUTE
#endif
Not all compiler support this attribute, so it may be defined to nothing.
XSFoundation version number
#define XS_VERSION ( XS_VERS_MAJ * 1000000 + XS_VERS_MIN * 10000 + XS_VERS_BUG * 100 + XS_VERS_PATCH )
Standardization of the weak compiler attribute
#if defined( __GNUC__ ) && ( ( __GNUC__ >= 4 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) )
#define XS_WEAK_ATTRIBUTE __attribute__( ( weak ) )
#else
#define XS_WEAK_ATTRIBUTE
#endif
Not all compiler support this attribute, so it may be defined to nothing.
Standardization of the weak import compiler attribute
#if defined( __GNUC__ ) && ( ( __GNUC__ >= 4 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) )
#define XS_WEAK_IMPORT_ATTRIBUTE __attribute__( ( weak_import ) )
#else
#if defined( __MWERKS__ ) && ( __MWERKS__ >= 0x3205 )
#define XS_WEAK_IMPORT_ATTRIBUTE __attribute__( ( weak_import ) )
#else
#define XS_WEAK_IMPORT_ATTRIBUTE
#endif
#endif
Not all compiler support this attribute, so it may be defined to nothing.