CLibs
Loading...
Searching...
No Matches
misc.h File Reference
#include "attributes.h"
#include "extra_types.h"

Go to the source code of this file.

Macros

#define UNUSED(UNUSEDARG)
 Stops those pesky unused variable compiler warnings/errors.
#define STRLEN(STRING)
 For string literals.
#define countof(array)
 Number of elements in an array (stack-allocated)
#define cmpeq(cmp_retval)
 Evaluates the cmp function as true if the elements are equal.
#define DEFINE_CMP_FUNCTION(TYPE)

Functions

LibraryDefined uint64_t hash_func (const void *const data, const size_t nbytes)

Macro Definition Documentation

◆ cmpeq

#define cmpeq ( cmp_retval)
Value:
( ( cmp_retval ) == 0 )

Evaluates the cmp function as true if the elements are equal.

◆ countof

#define countof ( array)
Value:
( sizeof( array ) / sizeof *( array ) )

Number of elements in an array (stack-allocated)

◆ DEFINE_CMP_FUNCTION

#define DEFINE_CMP_FUNCTION ( TYPE)
Value:
LibraryDefined int cmp_##TYPE( const void *p1, const void *p2 ) \
{ \
TYPE val_1 = *( TYPE * ) p1; \
TYPE val_2 = *( TYPE * ) p2; \
\
if ( val_1 > val_2 ) \
return 1; \
if ( val_1 < val_2 ) \
return -1; \
return 0; \
}
#define LibraryDefined
Definition attributes.h:107

Creates a new static comparator function with limited visibility for already comparable numeric types.

TYPE has to be a single token since it's used to define the name of the function.

◆ STRLEN

#define STRLEN ( STRING)
Value:
( sizeof( STRING ) - 1 )

For string literals.

◆ UNUSED

#define UNUSED ( UNUSEDARG)
Value:
( ( void ) UNUSEDARG )

Stops those pesky unused variable compiler warnings/errors.

Function Documentation

◆ hash_func()

LibraryDefined uint64_t hash_func ( const void *const data,
const size_t nbytes )

Creates an arbitrary hash of any data of the specified length.

Used, for example, in set.h and dictionary.h.

Parameters
datapointer to data
nbytesnumber of bytes (chars) under the pointer
Returns
unsigned 64-bit int hash