]> git.itanic.dy.fi Git - sdl-planets/blob - utils.h
Merge branch 'master' into dirty_work
[sdl-planets] / utils.h
1 #ifndef _UTILS_H
2 #define _UTILS_H
3
4 #include <stddef.h>
5
6 #ifdef DEBUG
7 #define debug 1
8 #else
9 #define debug 0
10 #endif
11
12 #define MAX(a,b) ((a) > (b) ? (a) : (b))
13 #define MIN(a,b) ((a) < (b) ? (a) : (b))
14
15 /**
16  * container_of - cast a member of a structure out to the containing structure
17  * @ptr:        the pointer to the member.
18  * @type:       the type of the container struct this is embedded in.
19  * @member:     the name of the member within the struct.
20  *
21  */
22 #define container_of(ptr, type, member) ({                      \
23         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
24         (type *)( (char *)__mptr - offsetof(type,member) );})
25
26 #endif