Macros

API attributes

ULIB_BEGIN_DECLS

Marks the beginning of declarations.

ULIB_END_DECLS

Marks the end of declarations.

ULIB_API

Marks public API, whose symbols should be exported.

ULIB_INLINE

Marks inline function definitions.

ULIB_PURE

Marks pure functions.

A pure function is a function that has no effect on the state of the program other than returning a value.

Note

This lets the compiler sometimes produce more optimized code.

ULIB_CONST

Marks const functions.

A const function is a pure function whose return value is not affected by changes to the state of the program.

Note

This lets the compiler sometimes produce more optimized code.

Warning

Should not be used on functions that accept pointer arguments, unless the contents of the pointed-to memory never change between successive invocations.

ULIB_NORETURN

Marks functions that do not return.

ULIB_DEPRECATED(msg)

Marks deprecated APIs.

Deprecated APIs are usually replaced by alternatives, and will be removed in later major versions of the library.

Parameters:
  • msg – Deprecation message.

ULIB_DEPRECATED_MACRO

Marks deprecated macros.

Deprecated macros are usually replaced by alternatives, and will be removed in later major versions of the library.

Debug and assertions

usrc_loc_init

Initializer for the current source code location.

ULIB_DEBUG

Signals that the code is compiled in debug mode.

ulib_assert(exp)

Asserts that exp is true.

If the assertion fails, execution is aborted.

Note

uLib assertions are enabled only for analyzers, or if ULIB_DEBUG is defined.

Parameters:
  • expboolean expression Boolean expression.

ulib_analyzer_assert(exp)

Give hints to static analyzers, asserting that exp is true.

Parameters:
  • expboolean expression Boolean expression.

struct USrcLoc
#include “udebug.h”

Source code location.

Public Members

char const *file

File name.

char const *func

Function name.

int line

Line number.

Warning suppression

ulib_unused

Suppresses unused variable warnings.

ULIB_SUPPRESS_BEGIN(compiler)

Begins the suppression of compiler warnings.

Parameters:
  • compiler – The compiler for which the warnings are being suppressed. Allowed values: GCC, CLANG, GNUC, MSVC.

ULIB_SUPPRESS(compiler, warning)

Suppresses the specified compiler warning.

Parameters:
  • compiler – The compiler for which the warnings are being suppressed. Allowed values: GCC, CLANG, GNUC, MSVC.

  • warning – The warning to suppress.

ULIB_SUPPRESS_END(compiler)

Ends the suppression of compiler warnings.

Parameters:
  • compiler – The compiler for which the warnings are being suppressed. Allowed values: GCC, CLANG, GNUC, MSVC.

ULIB_SUPPRESS_ONE(compiler, warning)

Begins the suppression of the specified compiler warning.

Parameters:
  • compiler – The compiler for which the warnings are being suppressed. Allowed values: GCC, CLANG, GNUC, MSVC.

  • warning – The warning to suppress.

Utilities

ulib_swap(T, x, y)

Swaps the contents of two variables.

Parameters:
  • T – Variable type.

  • x – First variable.

  • y – Second variable.

ulib_array_count(array)

Returns the number of elements of an array.

Parameters:
  • array – The array.

Returns:

Number of elements.

ulib_struct_init

C and C++ compatible struct initializer.

ULIB_MACRO_CONCAT(a, b)

Concatenates the a and b tokens, allowing a and b to be macro-expanded.

Parameters:
  • atoken First token.

  • btoken Second token.

ULIB_MACRO_STRINGIZE(a)

Stringizes the argument, allowing it to be macro-expanded.

Parameters:
  • amacro Macro to be stringized.

ULIB_PRAGMA(msg)

Pragma directive that allows macro expansion.

Parameters:
  • msg – Pragma directive.

ULIB_FILE_NAME

Expands to the name of the current file, if available, otherwise to its full path.

ulib_likely(exp)

Hint the branch predictor that exp is likely true.

Parameters:
  • expboolean expression Boolean expression.

ulib_unlikely(exp)

Hint the branch predictor that exp is likely false.

Parameters:
  • expboolean expression Boolean expression.

ulib_noop

No-op macro.

ulib_noop_func(...)

No-op function macro.

Parameters:
  • ... – Arguments (ignored).