Data Structures Lerax  v3.0-104-ge031
Opinionated Data Structures & Algorithms
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
16#include <stdio.h>
17#include <stdlib.h>
18
19// wondering why the `static` here?
20// the inline is just to expand as macro instead to define a function
21// here is the reason:
22// https://stackoverflow.com/questions/9428433/small-functions-defined-in-header-files-inline-or-static
23// basically is to avoid multiple definitions problem when this unit is included
24// in several sources and later is linked together.
25// yes, in this case the include guard is not enough.
26// but this is bad?
27
28
37static inline void check_alloc(void *p) {
38 if (p == NULL) {
39 puts("Memory allocation error.");
40 exit(EXIT_FAILURE);
41 }
42}
43
44
45#endif