csnip  0.1
Macros | Functions
Utilities

Simple utilities that are frequently used. More...

Macros

#define csnip_Tswap(type, a, b)
 Swap two variables, type explicitly specified.
 
#define csnip_Swap(a, b)
 Swap two variables. More...
 
#define csnip_Cswap(a, b)
 Swap two variables using memcpy(). More...
 
#define csnip_Min(a, b)    ((a) < (b) ? (a) : (b))
 Minimum of 2 values.
 
#define csnip_Max(a, b)    ((a) > (b) ? (a) : (b))
 Maximum of 2 values.
 
#define csnip_Static_len(a)   (sizeof(a) / sizeof(*(a)))
 Length of a C static array.
 
#define csnip_Fill_n(dest, len, val)
 Fill a range with values. More...
 
#define csnip_Fill(dest_begin, dest_end, val)    csnip_Fill_n(dest_begin, (dest_end) - (dest_begin), val)
 Fill a range with values. More...
 
#define csnip_Copy_n(src, len, dest)
 Copy a range from src to dest. More...
 
#define csnip_Copy(src_begin, src_end, dest)    csnip_Copy_n(src_begin, (src_end) - (src_begin), dest)
 Copy a range from src to dest. More...
 

Functions

size_t csnip_next_pow_of_2 (size_t a)
 Compute the next power of 2 of a number.
 

Detailed Description

The macros provided here provide very simple functionality that we have all seen defined and used many times. It would be better to keep reusing an existing definition of such things and so we provide one.

Macro Definition Documentation

◆ csnip_Copy

#define csnip_Copy (   src_begin,
  src_end,
  dest 
)     csnip_Copy_n(src_begin, (src_end) - (src_begin), dest)

This is a version of Copy_n which takes an (exclusive) end pointer instead of a length.

◆ csnip_Copy_n

#define csnip_Copy_n (   src,
  len,
  dest 
)

Copy src[0], ..., src[len - 1] to dest[0], ..., dest[len - 1].

len is evaluated once, while src and dest are evaluated once per assignment.

◆ csnip_Cswap

#define csnip_Cswap (   a,
 
)

This works assuming the variables in question are not register variables.

◆ csnip_Fill

#define csnip_Fill (   dest_begin,
  dest_end,
  val 
)     csnip_Fill_n(dest_begin, (dest_end) - (dest_begin), val)

This is a version of Fill_n which takes an (exclusive) end pointer instead of a length.

◆ csnip_Fill_n

#define csnip_Fill_n (   dest,
  len,
  val 
)

Set dest[0], ..., dest[len - 1] to the value val.

len is evaluated once; dest and val are evaluated "len" times, once for each assignment. Assignments are made in increasing index order.

◆ csnip_Swap

#define csnip_Swap (   a,
 
)
Note
This assumes the typeof(.) keyword is available, which is not in any of the C standards but known by many, but not all, compilers.