ic-macros  0.1.5
assert_type.h File Reference
#include <stdint.h>
#include "ic_macros/assert_constant.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IC_IS_TYPE(type, expr)   __builtin_types_compatible_p(type, __typeof__(expr))
 Compile-time check if expr is type. More...
 
#define IC_ASSERT_TYPE(type, expr)    IC_BUILD_ASSERT(IC_IS_TYPE(type, expr), #expr " is not of type " #type)
 Compile-time assertion that expr is type. More...
 
#define IC_REQUIRE_TYPE(type, expr)
 Compile-time assertion that expr is type returning expr. More...
 
#define IC_IS_UINT(expr)
 Compile-time constant check if expr is an unsigned integer. More...
 
#define IC_Z_REQUIRE_UINT(expr)
 Compile-time require expr is an unsigned integer. More...
 
#define IC_REQUIRE_UINT(expr)
 Compile-time constant require unsigned integer. More...
 
#define IC_IS_INT(expr)
 Compile-time check if expr is a signed integer. More...
 
#define IC_REQUIRE_INT(expr)
 Compile-time constant require signed integer. More...
 
#define IC_IS_FP(expr)
 Compile-time constant check if expr is a floating point number. More...
 
#define IC_REQUIRE_FP(expr)
 Compile-time constant require floating point number. More...
 

Macro Definition Documentation

◆ IC_ASSERT_TYPE

#define IC_ASSERT_TYPE (   type,
  expr 
)     IC_BUILD_ASSERT(IC_IS_TYPE(type, expr), #expr " is not of type " #type)

Compile-time assertion that expr is type.

Parameters
typeThe expected type.
exprThe expression.
Note
This will evaluate the expression once.

Definition at line 32 of file assert_type.h.

◆ IC_IS_FP

#define IC_IS_FP (   expr)
Value:
({ \
IC_ASSERT_CONSTANT(expr); \
(__builtin_types_compatible_p(float, __typeof__(expr)) \
|| __builtin_types_compatible_p(double, __typeof__(expr)) \
|| __builtin_types_compatible_p(long double, __typeof__(expr))); \
})

Compile-time constant check if expr is a floating point number.

Parameters
exprThe expression.
Note
This requires that the expression is a compile-time constant to prevent multiple runtime evaluations of the expression.
Returns
1 if expr is a floating point number, 0 otherwise.

Definition at line 143 of file assert_type.h.

◆ IC_IS_INT

#define IC_IS_INT (   expr)
Value:
({ \
IC_ASSERT_CONSTANT(expr); \
_IC_IS_INT(expr); \
})

Compile-time check if expr is a signed integer.

Parameters
exprThe expression.
Note
This requires that the expression is a compile-time constant to prevent multiple runtime evaluations of the expression.
Returns
1 if expr is a signed integer, 0 otherwise.

Definition at line 117 of file assert_type.h.

◆ IC_IS_TYPE

#define IC_IS_TYPE (   type,
  expr 
)    __builtin_types_compatible_p(type, __typeof__(expr))

Compile-time check if expr is type.

Parameters
typeThe type.
exprThe expression.
Returns
1 if the expression is of type, else 0.
Note
This will evaluate the expression once.

Definition at line 24 of file assert_type.h.

◆ IC_IS_UINT

#define IC_IS_UINT (   expr)
Value:
({ \
IC_ASSERT_CONSTANT(expr); \
_IC_IS_UINT(expr); \
})

Compile-time constant check if expr is an unsigned integer.

Parameters
exprThe expression.
Note
This requires that the expression is a compile-time constant to prevent multiple runtime evaluations of the expression.
Returns
1 if expr is an unsigned integer, 0 otherwise.

Definition at line 67 of file assert_type.h.

◆ IC_REQUIRE_FP

#define IC_REQUIRE_FP (   expr)
Value:
({ \
IC_BUILD_ASSERT(IC_IS_FP(IC_REQUIRE_CONSTANT(expr))); \
expr; \
})
#define IC_REQUIRE_CONSTANT(expr)
Require that the expression is a compile-time constant before returning it unchanged.
#define IC_IS_FP(expr)
Compile-time constant check if expr is a floating point number.
Definition: assert_type.h:143

Compile-time constant require floating point number.

Parameters
exprThe expression.
Note
This requires that the expression is a compile-time constant to prevent multiple runtime evaluations of the expression.
Returns
The expression.

Definition at line 158 of file assert_type.h.

◆ IC_REQUIRE_INT

#define IC_REQUIRE_INT (   expr)
Value:
({ \
IC_BUILD_ASSERT(IC_IS_INT(expr), #expr " is not a signed integer type"); \
expr; \
})
#define IC_IS_INT(expr)
Compile-time check if expr is a signed integer.
Definition: assert_type.h:117

Compile-time constant require signed integer.

Parameters
exprThe expression.
Note
This requires that the expression is a compile-time constant to prevent multiple runtime evaluations of the expression.
Returns
The expression.

Definition at line 130 of file assert_type.h.

◆ IC_REQUIRE_TYPE

#define IC_REQUIRE_TYPE (   type,
  expr 
)
Value:
({ \
IC_REQUIRE_CONSTANT(expr); \
IC_ASSERT_TYPE(type, expr); \
expr; \
})

Compile-time assertion that expr is type returning expr.

Parameters
typeThe expected type.
exprThe expression.
Note
This requires that the expression is a compile-time constant to prevent multiple runtime evaluations of the expression.

Definition at line 42 of file assert_type.h.

◆ IC_REQUIRE_UINT

#define IC_REQUIRE_UINT (   expr)
Value:
({ \
IC_BUILD_ASSERT(IC_IS_UINT(expr), #expr " is not an unsigned integer type"); \
expr; \
})
#define IC_IS_UINT(expr)
Compile-time constant check if expr is an unsigned integer.
Definition: assert_type.h:67

Compile-time constant require unsigned integer.

Parameters
exprThe expression.
Note
This requires that the expression is a compile-time constant to prevent multiple runtime evaluations of the expression.
Returns
The expression.

Definition at line 93 of file assert_type.h.

◆ IC_Z_REQUIRE_UINT

#define IC_Z_REQUIRE_UINT (   expr)
Value:
({ \
__auto_type const _ic_z_is_uint_expr_ = (expr); \
IC_BUILD_ASSERT(_IC_IS_UINT(expr)); \
_ic_z_is_uint_expr_; \
})

Compile-time require expr is an unsigned integer.

Parameters
exprThe expression.
Note
Expression is evaluated once and returned after evaluation.
Returns
The evaluated expression.

Definition at line 79 of file assert_type.h.