-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeclaration.h
More file actions
42 lines (29 loc) · 1.04 KB
/
declaration.h
File metadata and controls
42 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef DECLARATION_H
#define DECLARATION_H
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
// declaration macros
#define DeclareThing(what, name, block) \
typedef what _ ## name name; \
what _ ## name block
#define DeclareType(name, block) \
DeclareThing(struct, name, block)
#define DeclareUnion(name, block) \
DeclareThing(union, name, block)
#define ArrayAttribute(type, name) \
type * name; \
int n_ ## name
// helper macros for implementation
#define Allocate(type, name) \
type *name = calloc(1, sizeof(type)); \
if(NULL == name) { \
perror("calloc()"); \
abort(); \
}
#define Destroy(type, name) \
memset(name, 0, sizeof(type)); \
free(name); \
name = NULL
#define AllocateType(type) calloc(1, sizeof(type))
#endif