ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Macros | Typedefs | Functions
common.h File Reference

Common definitions and feature checks. More...

#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>

Go to the source code of this file.

Macros

#define UCX_VERSION_MAJOR   3
 Major UCX version as integer constant.
 
#define UCX_VERSION_MINOR   1
 Minor UCX version as integer constant.
 
#define UCX_VERSION   (((UCX_VERSION_MAJOR)<<16)|UCX_VERSION_MINOR)
 Version constant which ensures to increase monotonically.
 
#define CX_WORDSIZE   64
 The address width in bits on this platform.
 
#define __attribute__(x)
 Removes GNU C attributes where they are not supported.
 
#define cx_attr_nonnull   __attribute__((__nonnull__))
 All pointer arguments must be non-NULL.
 
#define cx_attr_nonnull_arg(...)   __attribute__((__nonnull__(__VA_ARGS__)))
 The specified pointer arguments must be non-NULL.
 
#define cx_attr_returns_nonnull   __attribute__((__returns_nonnull__))
 The returned value is guaranteed to be non-NULL.
 
#define cx_attr_malloc   __attribute__((__malloc__))
 The attributed function always returns freshly allocated memory.
 
#define cx_attr_dealloc(...)
 Not supported in clang.
 
#define cx_attr_dealloc_ucx   cx_attr_dealloc(cxFree, 2)
 Shortcut to specify cxFree() as deallocator.
 
#define cx_attr_allocsize(...)   __attribute__((__alloc_size__(__VA_ARGS__)))
 Specifies the parameters from which the allocation size is calculated.
 
#define cx_attr_access(mode, ...)
 No support for access attribute in GCC < 10.
 
#define cx_attr_cstr_arg(idx)
 No support for null_terminated_string_arg in clang or GCC below 14.
 
#define cx_attr_access_r(...)   cx_attr_access(__read_only__, __VA_ARGS__)
 Specifies that the function will only read through the given pointer.
 
#define cx_attr_access_rw(...)   cx_attr_access(__read_write__, __VA_ARGS__)
 Specifies that the function will read and write through the given pointer.
 
#define cx_attr_access_w(...)   cx_attr_access(__write_only__, __VA_ARGS__)
 Specifies that the function will only write through the given pointer.
 
#define cx_attr_unused   __attribute__((__unused__))
 Do not warn about unused variable.
 
#define cx_attr_nodiscard   __attribute__((__warn_unused_result__))
 Warn about discarded return value.
 
#define cx_attr_export
 Only used for building Windows DLLs.
 
#define cx_nmemb(arr)   (sizeof(arr)/sizeof((arr)[0]))
 Determines the number of members in a static C array.
 
#define cx_szmul(a, b, result)   cx_szmul_impl(a, b, result)
 Performs a multiplication of size_t values and checks for overflow.
 

Typedefs

typedef size_t(* cx_write_func) (const void *, size_t, size_t, void *)
 Function pointer compatible with fwrite-like functions.
 
typedef size_t(* cx_read_func) (void *, size_t, size_t, void *)
 Function pointer compatible with fread-like functions.
 

Functions

int cx_szmul_impl (size_t a, size_t b, size_t *result)
 Implementation of cx_szmul() when no compiler builtin is available.
 

Detailed Description

Common definitions and feature checks.

Author
Mike Becker
Olaf Wintermann

Macro Definition Documentation

◆ cx_attr_access_r

#define cx_attr_access_r ( ...)    cx_attr_access(__read_only__, __VA_ARGS__)

Specifies that the function will only read through the given pointer.

Takes one or two arguments: the index of the pointer and (optionally) the index of another argument specifying the maximum number of accessed bytes.

◆ cx_attr_access_rw

#define cx_attr_access_rw ( ...)    cx_attr_access(__read_write__, __VA_ARGS__)

Specifies that the function will read and write through the given pointer.

Takes one or two arguments: the index of the pointer and (optionally) the index of another argument specifying the maximum number of accessed bytes.

◆ cx_attr_access_w

#define cx_attr_access_w ( ...)    cx_attr_access(__write_only__, __VA_ARGS__)

Specifies that the function will only write through the given pointer.

Takes one or two arguments: the index of the pointer and (optionally) the index of another argument specifying the maximum number of accessed bytes.

◆ cx_nmemb

#define cx_nmemb ( arr)    (sizeof(arr)/sizeof((arr)[0]))

Determines the number of members in a static C array.

Attention
never use this to determine the size of a dynamically allocated array.
Parameters
arrthe array identifier
Returns
the number of elements

◆ cx_szmul

#define cx_szmul ( a,
b,
result )   cx_szmul_impl(a, b, result)

Performs a multiplication of size_t values and checks for overflow.

Parameters
a(size_t) first operand
b(size_t) second operand
result(size_t*) a pointer to a variable, where the result should be stored
Return values
zerosuccess
non-zerothe multiplication would overflow

Function Documentation

◆ cx_szmul_impl()

int cx_szmul_impl ( size_t a,
size_t b,
size_t * result )

Implementation of cx_szmul() when no compiler builtin is available.

Do not use in application code.

Parameters
afirst operand
bsecond operand
resulta pointer to a variable, where the result should be stored
Return values
zerosuccess
non-zerothe multiplication would overflow