Garmin Fleet Management Controller  2.19.0
util_macros.h File Reference

Basic utility macros for low-level functions. More...

Go to the source code of this file.

Macros

#define _compiler_assert(_e, _m)   struct tokcat( __, tokcat( _m, __LINE__ ) ) { int _ : ( (_e) ? 1 : 0 ); }
 Compile time assert. More...
 
#define _tokcat(_x, _y)    _x ## _y
 Concatenate two tokens. Do not use directly. More...
 
#define allbitset(_val, _mask)    ( ( (_val) & (_mask) ) == (_mask) )
 True if all mask bits are set in the specified value. More...
 
#define anybitset(_val, _mask)    ( ( (_val) & (_mask) ) != 0 )
 True if any mask bits are set in the specified value. More...
 
#define clrbit(_b)    ( ~setbit( _b ) )
 A bit mask with one bit cleared and the rest set. More...
 
#define clrbits(_b, _len)    ( ~setbits( (_b), (_len) ) )
 A bit mask with several bits cleared and the rest set. More...
 
#define cnt_of_array(_a)    ( sizeof( (_a) ) / sizeof( (_a)[0] ) )
 The number of elements in _a. More...
 
#define compiler_assert(_e)    _compiler_assert( _e, _UTIL_H_ )
 Compile time assert. More...
 
#define max_sint_val(_t)    ( setbits( 0, ( sizeof( _t ) * 8 ) - 1 ) )
 The maximum signed integer that can be stored in a type. More...
 
#define max_uint_val(_t)    ( setbits( 0, ( sizeof( _t ) * 8 ) ) )
 The maximum unsigned integer that can be stored in a type. More...
 
#define maxval(_x, _y)    ( (_x) > (_y) ? (_x) : (_y) )
 The larger of _x and _y. More...
 
#define min_sint_val(_t)    ( ~max_sint_val( _t ) )
 The minimum signed integer that can be stored in a type. More...
 
#define minval(_x, _y)    ( (_x) < (_y) ? (_x) : (_y) )
 The smaller of _x and _y. More...
 
#define offset_of(_s, _m)    ( (unsigned char *)&( ( (_s *)0 )->_m ) - (unsigned char *)0 )
 The offset of _m from the beginning of _s. More...
 
#define returnif(_check)
 Return if a condition is true. More...
 
#define returnif_v(_check, _value)
 Return a value if a condition is true. More...
 
#define setbit(_b)    ( (unsigned)1 << (_b) )
 A bit mask with one bit set and the rest cleared. More...
 
#define setbits(_b, _len)    ( ( ( 1U << ( (_len) - 1 ) ) - 1U + ( 1U << ( (_len) - 1 ) ) ) << (_b) )
 A bit mask with several bits set and the rest cleared. More...
 
#define tokcat(_x, _y)    _tokcat( _x, _y )
 Concatenate two tokens. More...
 

Detailed Description

Basic utility macros for low-level functions.

Definition in file util_macros.h.

Macro Definition Documentation

#define _compiler_assert (   _e,
  _m 
)    struct tokcat( __, tokcat( _m, __LINE__ ) ) { int _ : ( (_e) ? 1 : 0 ); }

Compile time assert.

Generate compiler error if _e is 0/false

Parameters
_eThe value to assert. This must evaluate to a compile-time constant.
_mA valid C identifier that represents the module name.

Definition at line 155 of file util_macros.h.

#define _tokcat (   _x,
  _y 
)    _x ## _y

Concatenate two tokens. Do not use directly.

Use tokcat() and not _tokcat(). _tokcat() only exists to allow tokcat() to get around preprocessor substitution rules.

Parameters
_xThe first token
_yThe second token

Definition at line 134 of file util_macros.h.

#define allbitset (   _val,
  _mask 
)    ( ( (_val) & (_mask) ) == (_mask) )

True if all mask bits are set in the specified value.

Parameters
_valThe value to test
_maskThe mask bits to check

Definition at line 52 of file util_macros.h.

#define anybitset (   _val,
  _mask 
)    ( ( (_val) & (_mask) ) != 0 )

True if any mask bits are set in the specified value.

Parameters
_valThe value to test
_maskThe mask bits to check

Definition at line 59 of file util_macros.h.

#define clrbit (   _b)    ( ~setbit( _b ) )

A bit mask with one bit cleared and the rest set.

Parameters
_bThe bit number that is cleared, counting from 0 as the LSB.

Definition at line 45 of file util_macros.h.

#define clrbits (   _b,
  _len 
)    ( ~setbits( (_b), (_len) ) )

A bit mask with several bits cleared and the rest set.

Parameters
_bThe lowest bit number that is cleared, counting from 0 as the LSB.
_lenThe number of bits that are cleared.

Definition at line 38 of file util_macros.h.

#define compiler_assert (   _e)    _compiler_assert( _e, _UTIL_H_ )

Compile time assert.

Generate compiler error if _e is 0/false

Parameters
_eThe value to assert. This must evaluate to a compile-time constant.

Definition at line 164 of file util_macros.h.

#define max_sint_val (   _t)    ( setbits( 0, ( sizeof( _t ) * 8 ) - 1 ) )

The maximum signed integer that can be stored in a type.

Parameters
_tThe data type to test.

Definition at line 65 of file util_macros.h.

#define max_uint_val (   _t)    ( setbits( 0, ( sizeof( _t ) * 8 ) ) )

The maximum unsigned integer that can be stored in a type.

Parameters
_tThe data type to test.

Definition at line 77 of file util_macros.h.

Referenced by Logger::logRawData(), and UTIL_data_is_uint32().

#define maxval (   _x,
  _y 
)    ( (_x) > (_y) ? (_x) : (_y) )

The larger of _x and _y.

Definition at line 100 of file util_macros.h.

Referenced by FmiApplicationLayer::rx().

#define min_sint_val (   _t)    ( ~max_sint_val( _t ) )

The minimum signed integer that can be stored in a type.

Parameters
_tThe data type to test.

Definition at line 71 of file util_macros.h.

#define returnif (   _check)
Value:
{ \
if( _check ) \
{ \
return; \
} \
} /* returnif */

Return if a condition is true.

Parameters
_checkThe boolean expression to check

Definition at line 106 of file util_macros.h.

#define returnif_v (   _check,
  _value 
)
Value:
{ \
if( _check ) \
{ \
return( _value ); \
} \
} /* returnif */

Return a value if a condition is true.

Parameters
_checkThe boolean expression to check
_valueThe value to return

Definition at line 119 of file util_macros.h.

Referenced by UTIL_convert_date_time_to_seconds().

#define setbit (   _b)    ( (unsigned)1 << (_b) )

A bit mask with one bit set and the rest cleared.

Parameters
_bThe bit number that is set, counting from 0 as the LSB.

Definition at line 30 of file util_macros.h.

Referenced by CWaypointDlg::getCatIds(), and FmiApplicationLayer::rx().

#define setbits (   _b,
  _len 
)    ( ( ( 1U << ( (_len) - 1 ) ) - 1U + ( 1U << ( (_len) - 1 ) ) ) << (_b) )

A bit mask with several bits set and the rest cleared.

Parameters
_bThe lowest bit number that is set, counting from 0 as the LSB.
_lenThe number of bits that are set.

Definition at line 24 of file util_macros.h.

#define tokcat (   _x,
  _y 
)    _tokcat( _x, _y )

Concatenate two tokens.

tokcat() returns a single C token that is the result of concatenating two tokens. For example, if "tokcat( _, __LINE__)" appears at line 123, it will be replaced with "_123" by the preprocessor. tokcat() is analogous to strcat().

Parameters
_xThe first token
_yThe second token

Definition at line 146 of file util_macros.h.