Pointers
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.
Safe pointers manipulation.
Header
#include <sewer/ptr.h>
Functions
void | ptr_get (...) |
void | ptr_dget (...) |
void | ptr_dget_no_null (...) |
void | ptr_assign (...) |
void | ptr_destopt (...) |
void | ptr_copyopt (...) |
The sewer library provides macros and functions for "safe" pointers manipulation. By "safe" we mean the fact that the SDK will detect improper pointer access just before a segment violation occurs. Does it make sense to detect a segment violation if the program is going to crash anyway? Pre-detection plays a very important role when running automated tests. Before the inevitable process closing, it will leave a note in the execution log.txt, indicating the reason for the crash.
- Use ptr_get to get the content of a pointer.
ptr_get ()
Access to the content of the pointer (dereference), verifying previously that it is not NULL
.
void ptr_get(type *ptr, type);
1 2 3 4 5 6 |
ptr | Pointer. |
type | Pointer type. |
ptr_dget ()
Access the content of a double pointer, invalidating it later.
void ptr_dget(type **ptr, type);
1 2 3 4 5 6 7 8 9 |
ptr | Double pointer. |
type | Pointer type. |
ptr_dget_no_null ()
Like ptr_dget
, but the content of the double pointer (*dptr
) can not be NULL
.
void ptr_dget_no_null(type **ptr, type);
1 2 3 4 5 6 7 8 |
Ctrl *create(Model **model, View **view) { // *model and *view can't be NULL Ctrl *ctrl = heap_new(Ctrl); ctrl->model = ptr_dget_no_null(model, Model); ctrl->view = ptr_dget_no_null(view, View); return ctrl; } |
ptr | Double pointer. |
type | Pointer type. |
ptr_assign ()
Assign content from one pointer to another, if the destination is not NULL
.
void
ptr_assign(dest,
src);
dest | Destination pointer. |
src | Source pointer. |
ptr_destopt ()
Destroy an object if not NULL
.
void ptr_destopt(FPtr_destroy func_destroy, type dptr, type);
1 2 3 4 5 6 |
cassert_no_null(dptr); if (*dptr != NULL) { func_destroy(*dptr); *dptr = NULL; } |
func_destroy | Destructor. |
dptr | Double pointer to the object to destroy. |
type | Object type. |
ptr_copyopt ()
Copy the object if not NULL
.
void ptr_copyopt(FPtr_copy func_copy, type ptr, type);
func_copy | Copy constructor. |
ptr | Object to copy (source). |
type | Object type. |