Data Structures Lerax 1.0.0
Essential Data Structures for C language
Loading...
Searching...
No Matches
check_alloc.h
Go to the documentation of this file.
1
12
13#ifndef CHECK_ALLOC_H
14#define CHECK_ALLOC_H
15#ifndef DS_UFC_H
16#include <stdio.h>
17#include <stdlib.h>
18#endif
19
20// wondering why the `static` here?
21// the inline is just to expand as macro instead to define a function
22// here is the reason:
23// https://stackoverflow.com/questions/9428433/small-functions-defined-in-header-files-inline-or-static
24// basically is to avoid multiple definitions problem when this unit is included
25// in several sources and later is linked together.
26// yes, in this case the include guard is not enough.
27// but this is bad?
28
29
30static inline void check_alloc(void *p) {
31 if (p == NULL) {
32 puts("Memory allocation error.");
33 exit(EXIT_FAILURE);
34 }
35}
36
37
38#endif