c_utils.h File Reference
#include <math.h>
#include <stdlib.h>
#include <stddef.h>
Go to the source code of this file.
|
Defines |
#define | UTIL_ASSERT(cond, msg) if(!(cond)) util_fail_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg) |
#define | UTIL_WARN(cond, msg) if(!(cond)) util_warn_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg) |
#define | UTIL_FAIL(msg) util_fail_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg) |
#define | ALLOC(ptr, type, num) do { (ptr)=(type *)util_malloc_((num)*sizeof(type)); } while (0) |
#define | RALLOC(type, num) ((type *)util_malloc_((num)*sizeof(type))) |
#define | DEALLOC(ptr) do { util_free_(ptr); (ptr)=NULL; } while(0) |
#define | SET_ARRAY(ptr, i1, i2, val) |
#define | COPY_ARRAY(src, dest, i1, i2) |
Detailed Description
Convenience functions
Copyright (C) 2008-2013 Max-Planck-Society
- Author:
- Martin Reinecke
- Note:
- This file should only be included from .c files, NOT from .h files.
Definition in file c_utils.h.
Define Documentation
#define UTIL_ASSERT |
( |
cond, |
|
|
msg |
|
) |
if(!(cond)) util_fail_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg) |
If cond is false, print an error message containing function name, source file name and line number of the call, as well as msg; then exit the program with an error status.
Definition at line 59 of file c_utils.h.
#define UTIL_WARN |
( |
cond, |
|
|
msg |
|
) |
if(!(cond)) util_warn_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg) |
If cond is false, print an warning containing function name, source file name and line number of the call, as well as msg.
Definition at line 64 of file c_utils.h.
#define UTIL_FAIL |
( |
msg |
|
) |
util_fail_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg) |
Print an error message containing function name, source file name and line number of the call, as well as msg; then exit the program with an error status.
Definition at line 70 of file c_utils.h.
#define ALLOC |
( |
ptr, |
|
|
type, |
|
|
num |
|
) |
do { (ptr)=(type *)util_malloc_((num)*sizeof(type)); } while (0) |
Allocate space for num objects of type type. Make sure that the allocation succeeded, else stop the program with an error. Return the resulting pointer in ptr.
Definition at line 77 of file c_utils.h.
#define RALLOC |
( |
type, |
|
|
num |
|
) |
((type *)util_malloc_((num)*sizeof(type))) |
Allocate space for num objects of type type. Make sure that the allocation succeeded, else stop the program with an error. Cast the resulting pointer to (type*).
Definition at line 83 of file c_utils.h.
#define DEALLOC |
( |
ptr |
|
) |
do { util_free_(ptr); (ptr)=NULL; } while(0) |
Deallocate ptr. It must have been allocated using ALLOC or RALLOC.
Definition at line 88 of file c_utils.h.
#define SET_ARRAY |
( |
ptr, |
|
|
i1, |
|
|
i2, |
|
|
val |
|
) |
|
Value:
do { \
ptrdiff_t cnt_; \
for (cnt_=(i1);cnt_<(i2);++cnt_) (ptr)[cnt_]=(val); \
} while(0)
Set the entries
ptr[i1] ...
ptr[i2-1] to
val.
Definition at line 99 of file c_utils.h.
#define COPY_ARRAY |
( |
src, |
|
|
dest, |
|
|
i1, |
|
|
i2 |
|
) |
|
Value:
do { \
ptrdiff_t cnt_; \
for (cnt_=(i1);cnt_<(i2);++cnt_) (dest)[cnt_]=(src)[cnt_]; \
} while(0)
Copy the entries
src[i1] ...
src[i2-1] to
dest[i1] ...
dest[i2-1].
Definition at line 107 of file c_utils.h.