CLibs
Loading...
Searching...
No Matches
pointer_utils.h File Reference
#include "attributes.h"
#include <stdarg.h>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define new(TYPE)
 Allocates memory for one (1) object of the specified type.
#define free_n(ptr)
 Frees the pointer and sets ptr to NULL
#define deref_as(type, var)
 Dereferences a pointer as if it was a pointer to type
#define deref_as_offset(type, var, offset)
 Dereferences a pointer as if it was a pointer to type with an offset.

Functions

LibraryDefined void free_all (int n,...)
LibraryDefined void free_and_null (void **n)

Macro Definition Documentation

◆ deref_as

#define deref_as ( type,
var )
Value:
( *( type * ) ( var ) )

Dereferences a pointer as if it was a pointer to type

◆ deref_as_offset

#define deref_as_offset ( type,
var,
offset )
Value:
( *( ( type * ) ( var ) ) + offset )

Dereferences a pointer as if it was a pointer to type with an offset.

◆ free_n

#define free_n ( ptr)
Value:
free_and_null( ( void ** ) &( ptr ) )
LibraryDefined void free_and_null(void **n)
Definition pointer_utils.h:45

Frees the pointer and sets ptr to NULL

◆ new

#define new ( TYPE)
Value:
calloc( 1, sizeof( TYPE ) )

Allocates memory for one (1) object of the specified type.

Function Documentation

◆ free_all()

LibraryDefined void free_all ( int n,
... )

Frees n pointers by calling free on each.

Parameters
nnumber of pointers
...pointers

◆ free_and_null()

LibraryDefined void free_and_null ( void ** n)
inline

Does free(*n) and sets *n = NULL

Parameters
npointer to pointer