There are functions in different files in my C program between which I want to communicate errors. For example:
MEMOERY_ALLOCATION_FAILED
, FILE_OPENING_FAILED
or NAME_NOT_VALID
.
I thought of creating an Error
linked list like so:
typedef struct Error {
char *message;
struct Error *next;
};
And pass this linked list to every function so the functions can add errors if those occur, like so:
int foo(int x, Error *list);
But there is a problem with this one, and that is when allocating space for a new Error
, that could fail and the function that called that function could not receive that information.
What are some useful ideas to solve such a problem?
Note that I cannot retuen error codes because:
- A function can append more than ine error
- The functions nees to return other things