RTEMS
Files | Macros
Base Definitions

This group contains basic macros and defines to give access to compiler-specific features. More...

Files

file  basedefs.h
 This header file provides basic definitions used by the API and the implementation.
 

Macros

#define RTEMS_CONCAT(_x, _y)   _x##_y
 Concatenates _x and _y without expanding. More...
 
#define RTEMS_TYPEOF_REFX(_level, _target)   __typeof__(_level(union { int z; __typeof__(_target) x; }){0}.x)
 Returns the type of a pointer reference of the specified level to the specified type. More...
 
#define RTEMS_STRING(_x)   #_x
 Stringifies _x without expanding. More...
 
#define RTEMS_XCONCAT(_x, _y)   RTEMS_CONCAT( _x, _y )
 Concatenates expansion of _x and expansion of _y. More...
 
#define RTEMS_EXPAND(_token)   _token
 Helper macro to perform a macro expansion on the specified token. More...
 
#define RTEMS_DEPRECATED   __attribute__((__deprecated__))
 Instructs the compiler in a declaration to issue a warning whenever a variable, function, or type using this declaration will be used.
 
#define RTEMS_NO_RETURN   __attribute__((__noreturn__))
 Tells the compiler in a function declaration that this function does not return.
 
#define RTEMS_PACKED   __attribute__((__packed__))
 Instructs the compiler in a type definition to place members of a structure or union so that the memory required is minimized.
 
#define RTEMS_PURE   __attribute__((__pure__))
 Tells the compiler in a function declaration that this function has no effect except the return value and that the return value depends only on the value of parameters and/or global variables.
 
#define RTEMS_USED   __attribute__((__used__))
 Tells the compiler that a specific variable or function is used.
 
#define RTEMS_DEQUALIFY_DEPTHX(_ptr_level, _type, _var)
 Performs a type cast which removes qualifiers without warnings to the specified type for the specified variable. More...
 
#define RTEMS_XSTRING(_x)   RTEMS_STRING( _x )
 Stringifies the expansion of _x. More...
 
#define RTEMS_SYMBOL_NAME(_name)   RTEMS_EXPAND(_name)
 Constructs a symbol name. More...
 
#define RTEMS_ALIAS(_target)   __attribute__((__alias__(#_target)))
 Instructs the compiler to generate an alias to the specified target function. More...
 
#define RTEMS_ALIGN_DOWN(_value, _alignment)   ( ( _value ) & ~( ( _alignment ) - 1 ) )
 Returns the specified value aligned down to the specified alignment. More...
 
#define RTEMS_ALIGN_UP(_value, _alignment)   ( ( ( _value ) + ( _alignment ) - 1 ) & ~( ( _alignment ) - 1 ) )
 Returns the specified value aligned up to the specified alignment. More...
 
#define RTEMS_ALIGNED(_alignment)   __attribute__((__aligned__(_alignment)))
 Instructs the compiler in a declaration or definition to enforce the specified alignment. More...
 
#define RTEMS_ALLOC_ALIGN(_index)   __attribute__((__alloc_align__(_index)))
 Tells the compiler in a declaration that the memory allocation alignment parameter of this function is similar to aligned_alloc(). More...
 
#define RTEMS_ALLOC_SIZE(_index)   __attribute__((__alloc_size__(_index)))
 Tells the compiler in a declaration that the memory allocation size parameter of this function is similar to malloc(). More...
 
#define RTEMS_ALLOC_SIZE_2(_count_index, _size_index)   __attribute__((__alloc_size__(_count_index, _size_index)))
 Tells the compiler in a declaration that the memory allocation item count and item size parameter of this function is similar to calloc(). More...
 
#define RTEMS_ARRAY_SIZE(_array)   (sizeof(_array) / sizeof((_array)[0]))
 Returns the element count of the specified array. More...
 
#define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE   RTEMS_DEPRECATED
 Provided for backward compatibility.
 
#define RTEMS_COMPILER_MEMORY_BARRIER()   __asm__ volatile( "" ::: "memory" )
 This macro forbids the compiler to reorder read and write commands around it.
 
#define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE   RTEMS_NO_RETURN
 Provided for backward compatibility.
 
#define RTEMS_COMPILER_PACKED_ATTRIBUTE   RTEMS_PACKED
 Provided for backward compatibility.
 
#define RTEMS_COMPILER_PURE_ATTRIBUTE   RTEMS_PURE
 Provided for backward compatibility.
 
#define RTEMS_COMPILER_USED_ATTRIBUTE   RTEMS_USED
 Provided for backward compatibility.
 
#define RTEMS_CONST   __attribute__((__const__))
 Tells the compiler in a function declaration that this function has no effect except the return value and that the return value depends only on the value of parameters.
 
#define RTEMS_CONTAINER_OF(_m, _type, _member_name)   ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )
 Returns the pointer to the container of a specified member pointer. More...
 
#define RTEMS_DECLARE_GLOBAL_SYMBOL(_name)   extern char _name[]
 Declares a global symbol with the specified name. More...
 
#define RTEMS_DECONST(_type, _var)   RTEMS_DEQUALIFY_DEPTHX(*, _type, _var)
 Performs a type cast which removes const qualifiers without warnings to the specified type for the specified pointer variable. More...
 
#define RTEMS_DEFINE_GLOBAL_SYMBOL(_name, _value)
 Defines a global symbol with the specified name and value. More...
 
#define RTEMS_DEQUALIFY(_type, _var)   RTEMS_DEQUALIFY_DEPTHX(*, _type, _var)
 Performs a type cast which removes all qualifiers without warnings to the specified type for the specified pointer variable. More...
 
#define RTEMS_DEVOLATILE(_type, _var)   RTEMS_DEQUALIFY_DEPTHX(*, _type, _var)
 Performs a type cast which removes volatile qualifiers without warnings to the specified type for the specified pointer variable. More...
 
#define FALSE   0
 If FALSE is undefined, then FALSE is defined to 0.
 
#define RTEMS_HAVE_MEMBER_SAME_TYPE(_t_lhs, _m_lhs, _t_rhs, _m_rhs)
 Evaluates to true if the specified members of two types have compatible types, otherwise to false. More...
 
#define RTEMS_INLINE_ROUTINE   static __inline__
 Gives a hint to the compiler in a function declaration to inline this function.
 
#define RTEMS_MALLOCLIKE   __attribute__((__malloc__))
 Tells the compiler in a declaration that this function is a memory allocation function similar to malloc().
 
#define RTEMS_NO_INLINE   __attribute__((__noinline__))
 Instructs the compiler in a function declaration to not inline this function.
 
#define RTEMS_OBFUSCATE_VARIABLE(_var)   __asm__( "" : "+r" ( _var ) )
 Obfuscates the variable so that the compiler cannot perform optimizations based on the variable value. More...
 
#define RTEMS_PREDICT_FALSE(_exp)   __builtin_expect( ( _exp ), 0 )
 Returns the value of the specified integral expression and tells the compiler that the predicted value is false (1). More...
 
#define RTEMS_PREDICT_TRUE(_exp)   __builtin_expect( ( _exp ), 1 )
 Returns the value of the specified integral expression and tells the compiler that the predicted value is true (1). More...
 
#define RTEMS_PRINTFLIKE(_format_pos, _ap_pos)   __attribute__((__format__(__printf__, _format_pos, _ap_pos)))
 Tells the compiler in a declaration that this function expects printf()-like arguments. More...
 
#define RTEMS_RETURN_ADDRESS()   __builtin_return_address(0)
 Returns the return address of the current function. More...
 
#define RTEMS_SECTION(_section)   __attribute__((__section__(_section)))
 Instructs the compiler to place a specific variable or function in the specified section. More...
 
#define RTEMS_STATIC_ASSERT(_cond, _msg)
 Asserts at compile time that the specified condition is satisfied. More...
 
#define TRUE   1
 If TRUE is undefined, then TRUE is defined to 1.
 
#define RTEMS_UNUSED   __attribute__((__unused__))
 Tells the compiler that a specific variable or function is deliberately unused.
 
#define RTEMS_WARN_UNUSED_RESULT   __attribute__((__warn_unused_result__))
 Tells the compiler in a declaration that the result of this function should be used.
 
#define RTEMS_WEAK   __attribute__((__weak__))
 Tells the compiler in a function definition that this function should be weak. More...
 
#define RTEMS_WEAK_ALIAS(_target)   __attribute__((__weak__, __alias__(#_target)))
 Instructs the compiler to generate a weak alias to the specified target function. More...
 
#define RTEMS_ZERO_LENGTH_ARRAY   0
 This is a constant to declare zero-length arrays. More...
 

Detailed Description

This group contains basic macros and defines to give access to compiler-specific features.

Macro Definition Documentation

◆ RTEMS_ALIAS

#define RTEMS_ALIAS (   _target)    __attribute__((__alias__(#_target)))

Instructs the compiler to generate an alias to the specified target function.

Parameters
_targetis the target function name.

Definition at line 335 of file basedefs.h.

◆ RTEMS_ALIGN_DOWN

#define RTEMS_ALIGN_DOWN (   _value,
  _alignment 
)    ( ( _value ) & ~( ( _alignment ) - 1 ) )

Returns the specified value aligned down to the specified alignment.

Parameters
_valueis the value to align down.
_alignmentis the desired alignment in bytes. The alignment shall be a power of two, otherwise the returned value is undefined. The alignment parameter is evaluated twice.
Returns
The specified value aligned down to the specified alignment is returned.

Definition at line 356 of file basedefs.h.

◆ RTEMS_ALIGN_UP

#define RTEMS_ALIGN_UP (   _value,
  _alignment 
)    ( ( ( _value ) + ( _alignment ) - 1 ) & ~( ( _alignment ) - 1 ) )

Returns the specified value aligned up to the specified alignment.

Parameters
_valueis the value to align up.
_alignmentis the desired alignment in bytes. The alignment shall be a power of two, otherwise the returned value is undefined. The alignment parameter is evaluated twice.
Returns
The specified value aligned up to the specified alignment is returned.

Definition at line 375 of file basedefs.h.

◆ RTEMS_ALIGNED

#define RTEMS_ALIGNED (   _alignment)    __attribute__((__aligned__(_alignment)))

Instructs the compiler in a declaration or definition to enforce the specified alignment.

Parameters
_alignmentis the desired alignment in bytes.

Definition at line 389 of file basedefs.h.

◆ RTEMS_ALLOC_ALIGN

#define RTEMS_ALLOC_ALIGN (   _index)    __attribute__((__alloc_align__(_index)))

Tells the compiler in a declaration that the memory allocation alignment parameter of this function is similar to aligned_alloc().

Parameters
_indexis the allocation alignment parameter index (starting with one).

Definition at line 406 of file basedefs.h.

◆ RTEMS_ALLOC_SIZE

#define RTEMS_ALLOC_SIZE (   _index)    __attribute__((__alloc_size__(_index)))

Tells the compiler in a declaration that the memory allocation size parameter of this function is similar to malloc().

Parameters
_indexis the allocation size parameter index (starting with one).

Definition at line 422 of file basedefs.h.

◆ RTEMS_ALLOC_SIZE_2

#define RTEMS_ALLOC_SIZE_2 (   _count_index,
  _size_index 
)    __attribute__((__alloc_size__(_count_index, _size_index)))

Tells the compiler in a declaration that the memory allocation item count and item size parameter of this function is similar to calloc().

Parameters
_count_indexis the allocation item count parameter index (starting with one).
_size_indexis the allocation item size parameter index (starting with one).

Definition at line 442 of file basedefs.h.

◆ RTEMS_ARRAY_SIZE

#define RTEMS_ARRAY_SIZE (   _array)    (sizeof(_array) / sizeof((_array)[0]))

Returns the element count of the specified array.

Parameters
_arrayis the name of the array.
Returns
The element count of the specified array.

Definition at line 459 of file basedefs.h.

◆ RTEMS_CONCAT

#define RTEMS_CONCAT (   _x,
  _y 
)    _x##_y

Concatenates _x and _y without expanding.

Parameters
_xis the left hand side token of the concatenation.
_yis the right hand side token of the concatenation.
Returns
The concatenation of the tokens _x and _y.

Definition at line 105 of file basedefs.h.

◆ RTEMS_CONTAINER_OF

#define RTEMS_CONTAINER_OF (   _m,
  _type,
  _member_name 
)    ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )

Returns the pointer to the container of a specified member pointer.

Parameters
_mis the pointer to a member of the container.
_typeis the type of the container.
_member_nameis the designator name of the container member.
Returns
Returns the pointer to the container of a specified member pointer.

Definition at line 550 of file basedefs.h.

◆ RTEMS_DECLARE_GLOBAL_SYMBOL

#define RTEMS_DECLARE_GLOBAL_SYMBOL (   _name)    extern char _name[]

Declares a global symbol with the specified name.

This macro must be placed at file scope.

Parameters
_nameis the name of the global symbol. It shall be a valid designator.

Definition at line 565 of file basedefs.h.

◆ RTEMS_DECONST

#define RTEMS_DECONST (   _type,
  _var 
)    RTEMS_DEQUALIFY_DEPTHX(*, _type, _var)

Performs a type cast which removes const qualifiers without warnings to the specified type for the specified pointer variable.

Parameters
_typeis the target type of the cast.
_varis the pointer variable.

Definition at line 579 of file basedefs.h.

◆ RTEMS_DEFINE_GLOBAL_SYMBOL

#define RTEMS_DEFINE_GLOBAL_SYMBOL (   _name,
  _value 
)

Defines a global symbol with the specified name and value.

This macro shall be placed at file scope.

Parameters
_nameis the user defined name of the symbol. The name shall be a valid designator. On the name a macro expansion is performed and afterwards it is stringified.
_valueis the value of the symbol. On the value a macro expansion is performed and afterwards it is stringified. It shall expand to an integer expression understood by the assembler.

Definition at line 606 of file basedefs.h.

◆ RTEMS_DEQUALIFY

#define RTEMS_DEQUALIFY (   _type,
  _var 
)    RTEMS_DEQUALIFY_DEPTHX(*, _type, _var)

Performs a type cast which removes all qualifiers without warnings to the specified type for the specified pointer variable.

Parameters
_typeis the target type of the cast.
_varis the pointer variable.

Definition at line 621 of file basedefs.h.

◆ RTEMS_DEQUALIFY_DEPTHX

#define RTEMS_DEQUALIFY_DEPTHX (   _ptr_level,
  _type,
  _var 
)
Value:
__builtin_choose_expr(__builtin_types_compatible_p( \
RTEMS_TYPEOF_REFX(_ptr_level, _var), \
RTEMS_TYPEOF_REFX(_ptr_level, _type) \
) || __builtin_types_compatible_p(_type, void *), \
(_type)(_var), \
void * RTEMS_DEQUALIFY_types_not_compatible(void)
A not implemented function to trigger compile time errors with an error message.
#define RTEMS_TYPEOF_REFX(_level, _target)
Returns the type of a pointer reference of the specified level to the specified type.
Definition: basedefs.h:137

Performs a type cast which removes qualifiers without warnings to the specified type for the specified variable.

Parameters
_ptr_levelis the pointer indirection level expressed in *.
_typeis the target type of the cast.
_varis the variable.

Definition at line 272 of file basedefs.h.

◆ RTEMS_DEVOLATILE

#define RTEMS_DEVOLATILE (   _type,
  _var 
)    RTEMS_DEQUALIFY_DEPTHX(*, _type, _var)

Performs a type cast which removes volatile qualifiers without warnings to the specified type for the specified pointer variable.

Parameters
_typeis the target type of the cast.
_varis the pointer variable.

Definition at line 635 of file basedefs.h.

◆ RTEMS_EXPAND

#define RTEMS_EXPAND (   _token)    _token

Helper macro to perform a macro expansion on the specified token.

Parameters
_tokenis the token to expand.

Definition at line 182 of file basedefs.h.

◆ RTEMS_HAVE_MEMBER_SAME_TYPE

#define RTEMS_HAVE_MEMBER_SAME_TYPE (   _t_lhs,
  _m_lhs,
  _t_rhs,
  _m_rhs 
)
Value:
__builtin_types_compatible_p( \
__typeof__( ( (_t_lhs *) 0 )->_m_lhs ), \
__typeof__( ( (_t_rhs *) 0 )->_m_rhs ) \
)

Evaluates to true if the specified members of two types have compatible types, otherwise to false.

Parameters
_t_lhsis the left hand side type.
_m_lhsis the left hand side member.
_t_rhsis the right hand side type.
_m_rhsis the right hand side member.

Definition at line 665 of file basedefs.h.

◆ RTEMS_OBFUSCATE_VARIABLE

#define RTEMS_OBFUSCATE_VARIABLE (   _var)    __asm__( "" : "+r" ( _var ) )

Obfuscates the variable so that the compiler cannot perform optimizations based on the variable value.

The variable must be simple enough to fit into a register.

Parameters
_varis the variable to obfuscate.

Definition at line 729 of file basedefs.h.

◆ RTEMS_PREDICT_FALSE

#define RTEMS_PREDICT_FALSE (   _exp)    __builtin_expect( ( _exp ), 0 )

Returns the value of the specified integral expression and tells the compiler that the predicted value is false (1).

Parameters
_expis the expression.
Returns
The value of the expression.

Definition at line 747 of file basedefs.h.

◆ RTEMS_PREDICT_TRUE

#define RTEMS_PREDICT_TRUE (   _exp)    __builtin_expect( ( _exp ), 1 )

Returns the value of the specified integral expression and tells the compiler that the predicted value is true (1).

Parameters
_expis the expression.
Returns
The value of the expression.

Definition at line 765 of file basedefs.h.

◆ RTEMS_PRINTFLIKE

#define RTEMS_PRINTFLIKE (   _format_pos,
  _ap_pos 
)    __attribute__((__format__(__printf__, _format_pos, _ap_pos)))

Tells the compiler in a declaration that this function expects printf()-like arguments.

Parameters
_format_posis the position of the format parameter index (starting with one).
_ap_posis the position of the argument pointer parameter index (starting with one).

Definition at line 785 of file basedefs.h.

◆ RTEMS_RETURN_ADDRESS

#define RTEMS_RETURN_ADDRESS ( )    __builtin_return_address(0)

Returns the return address of the current function.

Returns
The return address of the current function.

Definition at line 801 of file basedefs.h.

◆ RTEMS_SECTION

#define RTEMS_SECTION (   _section)    __attribute__((__section__(_section)))

Instructs the compiler to place a specific variable or function in the specified section.

Parameters
_sectionis the section name as a string.

Definition at line 817 of file basedefs.h.

◆ RTEMS_STATIC_ASSERT

#define RTEMS_STATIC_ASSERT (   _cond,
  _msg 
)
Value:
struct rtems_static_assert_ ## _msg \
{ int rtems_static_assert_ ## _msg : (_cond) ? 1 : -1; }

Asserts at compile time that the specified condition is satisfied.

Parameters
_condis the condition this static assertion shall satisfy.
_msgis the error message in case the static assertion fails.

Definition at line 838 of file basedefs.h.

◆ RTEMS_STRING

#define RTEMS_STRING (   _x)    #_x

Stringifies _x without expanding.

Parameters
_xis the token to stringify.
Returns
The stringification of the token _x.

Definition at line 154 of file basedefs.h.

◆ RTEMS_SYMBOL_NAME

#define RTEMS_SYMBOL_NAME (   _name)    RTEMS_EXPAND(_name)

Constructs a symbol name.

Parameters
_nameis the user defined name of the symbol. The name shall be a valid designator. On the name a macro expansion is performed.

Definition at line 310 of file basedefs.h.

◆ RTEMS_TYPEOF_REFX

#define RTEMS_TYPEOF_REFX (   _level,
  _target 
)    __typeof__(_level(union { int z; __typeof__(_target) x; }){0}.x)

Returns the type of a pointer reference of the specified level to the specified type.

The reference type idea is based on libHX by Jan Engelhardt.

Parameters
_levelis the pointer indirection level expressed in *.
_targetis the reference target type.

Definition at line 137 of file basedefs.h.

◆ RTEMS_WEAK

#define RTEMS_WEAK   __attribute__((__weak__))

Tells the compiler in a function definition that this function should be weak.

Use this attribute for function definitions. Do not use it for function declarations.

Definition at line 909 of file basedefs.h.

◆ RTEMS_WEAK_ALIAS

#define RTEMS_WEAK_ALIAS (   _target)    __attribute__((__weak__, __alias__(#_target)))

Instructs the compiler to generate a weak alias to the specified target function.

Parameters
_targetis the target function name.

Definition at line 925 of file basedefs.h.

◆ RTEMS_XCONCAT

#define RTEMS_XCONCAT (   _x,
  _y 
)    RTEMS_CONCAT( _x, _y )

Concatenates expansion of _x and expansion of _y.

Parameters
_xis expanded first and then used as the left hand side token of the concatenation.
_yis expanded first and then used as the right hand side token of the concatenation.
Returns
The concatenation of the expansions of tokens _x and _y.

Definition at line 171 of file basedefs.h.

◆ RTEMS_XSTRING

#define RTEMS_XSTRING (   _x)    RTEMS_STRING( _x )

Stringifies the expansion of _x.

Parameters
_xis the token expand and stringify.
Returns
The stringification of the expansion of token _x.

Definition at line 295 of file basedefs.h.

◆ RTEMS_ZERO_LENGTH_ARRAY

#define RTEMS_ZERO_LENGTH_ARRAY   0

This is a constant to declare zero-length arrays.

Zero-length arrays are valid in C99 as flexible array members. C++11 does not allow flexible array members. Use the GNU extension which is also supported by other compilers.

Definition at line 945 of file basedefs.h.