Xenomai  3.0-rc7
compiler.h
1 /*
2  * Copyright (C) 2013 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _BOILERPLATE_COMPILER_H
19 #define _BOILERPLATE_COMPILER_H
20 
21 #include <stddef.h>
22 
23 #define container_of(ptr, type, member) \
24  ({ \
25  const __typeof__(((type *)0)->member) *__mptr = (ptr); \
26  (type *)((char *)__mptr - offsetof(type, member)); \
27  })
28 
29 #define __stringify_1(x...) #x
30 #define __stringify(x...) __stringify_1(x)
31 
32 #ifndef likely
33 #define likely(x) __builtin_expect(!!(x), 1)
34 #define unlikely(x) __builtin_expect(!!(x), 0)
35 #endif
36 
37 #ifndef __noreturn
38 #define __noreturn __attribute__((__noreturn__))
39 #endif
40 
41 #ifndef __must_check
42 #define __must_check __attribute__((__warn_unused_result__))
43 #endif
44 
45 #ifndef __weak
46 #define __weak __attribute__((__weak__))
47 #endif
48 
49 #ifndef __maybe_unused
50 #define __maybe_unused __attribute__((__unused__))
51 #endif
52 
53 #ifndef __aligned
54 #define __aligned(__n) __attribute__((aligned (__n)))
55 #endif
56 
57 #endif /* _BOILERPLATE_COMPILER_H */