c-template
returns.h
Go to the documentation of this file.
1 /*! @file errors.h
2  * @brief provides a C equivlent of golang function returns
3  * it enables returning two values from function call, one being an error (if any) and one being data if any
4 */
5 
6 #pragma once
7 
8 #include "errors.h"
9 #include <stdlib.h>
10 
11 /*! @brief allows returning both a value and error message from a function call
12  * useful as it makes it easier to provid better error message and handling similar to go
13 */
14 typedef struct {
15  // value is the data returned by a function call (if any)
16  void *value;
17  // if not a NULL pointer than it means the function call errored
18  // and the value struct member will be a NULL pointer
20 } cg_return;
21 
22 /*! @brief creates a new cg_return struct
23 */
24 cg_return *new_cg_return(void *value, cg_error *err);
25 /*! @brief frees up resources associated with an instance of cg_return
26 */
27 void free_cg_return(cg_return *ret);
cg_return::value
void * value
Definition: returns.h:16
cg_return::err
cg_error * err
Definition: returns.h:19
errors.h
golang like error handling
cg_return
allows returning both a value and error message from a function call useful as it makes it easier to ...
Definition: returns.h:14
new_cg_return
cg_return * new_cg_return(void *value, cg_error *err)
creates a new cg_return struct
Definition: returns.c:5
cg_error
Definition: errors.h:14
free_cg_return
void free_cg_return(cg_return *ret)
frees up resources associated with an instance of cg_return
Definition: returns.c:24