Macros Reference

File
XSFoundation/include/XS/Macros.h
Author
Jean-David Gadina - www.xs-labs.com
Copyright
© (c) 2020 - Jean-David Gadina - www.xs-labs.com
Date
Sunday, September 27, 2020
Includes
None

Overview

XSFoundation macros

Macros

__func__

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

XS_ABS

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

Parameters
  • _a_
    The value
Return value

The absolute value of the value

XS_AUTORELEASED

Marker for methods that return auto-released objects

#define XS_AUTORELEASED

XS_CONST_ATTRIBUTE

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

Discussion

Not all compiler support this attribute, so it may be defined to nothing.

XS_DEPRECATED_ATTRIBUTE

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

Discussion

Not all compiler support this attribute, so it may be defined to nothing.

XS_EXPORT

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

XS_EXTERN

Standardization of the extern keyword

#if defined( __cplusplus ) #define XS_EXTERN extern "C" #else #define XS_EXTERN extern #endif

XS_EXTERN_C_BEGIN

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

XS_EXTERN_C_END

Substitution for 'extern "C" {' end, when compiling with C++

#ifdef __cplusplus #define XS_EXTERN_C_END } #else #define XS_EXTERN_C_END #endif

XS_FORMAT_ATTRIBUTE

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

Discussion

Not all compiler support this attribute, so it may be defined to nothing.

XS_INLINE

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

XS_MAX

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

Parameters
  • _a_
    The first value
  • _b_
    The second value
Return value

The maximum value of the two values

XS_MIN

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

Parameters
  • _a_
    The first value
  • _b_
    The second value
Return value

The minimum value of the two values

XS_NORETURN_ATTRIBUTE

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

Discussion

Not all compiler support this attribute, so it may be defined to nothing.

XS_PATH_MAX

Maximum length for a path

#if defined( _WIN32 ) #define XS_PATH_MAX MAX_PATH #else #define XS_PATH_MAX PATH_MAX #endif

XS_PATH_SEPARATOR

The separator character used in paths

#if defined( _WIN32 ) #define XS_PATH_SEPARATOR '\\' #else #define XS_PATH_SEPARATOR '/' #endif

XS_SWAP_16

Swap endiannes of a 16 bits value

#define XS_SWAP_16( _value_ ) ( ( ( ( uint16_t )( _value_ ) >> 8 ) & 0x00FF ) | ( ( ( uint16_t )( _value_ ) << 8 ) & 0xFF00 ) )

Parameters
  • _value_
    The value to swap

XS_SWAP_32

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 ) )

Parameters
  • _value_
    The value to swap

XS_SWAP_64

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 ) )

Parameters
  • _value_
    The value to swap

XS_UNAVAILABLE_ATTRIBUTE

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

Discussion

Not all compiler support this attribute, so it may be defined to nothing.

XS_VERSION

XSFoundation version number

#define XS_VERSION ( XS_VERS_MAJ * 1000000 + XS_VERS_MIN * 10000 + XS_VERS_BUG * 100 + XS_VERS_PATCH )

XS_VERSION_BUGFIX

XSFoundation bugfix version number

#define XS_VERSION_BUGFIX 0

XS_VERSION_MAJ

XSFoundation major version number

#define XS_VERSION_MAJ 1

XS_VERSION_MIN

XSFoundation minor version number

#define XS_VERSION_MIN 0

XS_VERSION_PATCH

XSFoundation patch level version number

#define XS_VERSION_PATCH 0

XS_VERSION_STR

XSFoundation version number string

#define XS_VERSION_STR "1.0.0-0"

XS_WEAK_ATTRIBUTE

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

Discussion

Not all compiler support this attribute, so it may be defined to nothing.

XS_WEAK_IMPORT_ATTRIBUTE

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

Discussion

Not all compiler support this attribute, so it may be defined to nothing.