1 /*****************************************************************************
2  * Copyright ©2017-2019 Gemalto – a Thales Company. All rights Reserved.
3  *
4  * This copy is licensed under the Apache License, Version 2.0 (the "License");
5  * You may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *     http://www.apache.org/licenses/LICENSE-2.0 or https://www.apache.org/licenses/LICENSE-2.0.html
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  * See the License for the specific language governing permissions and limitations under the License.
11 
12  ****************************************************************************/
13 
14 /**
15  * @file
16  * $Author$
17  * $Revision$
18  * $Date$
19  *
20  * Compiler specific definition. Currently target gcc and clang.
21  *
22  * We need offsetof() and containerof().
23  *
24  */
25 
26 #ifndef COMPILER_H
27 #define COMPILER_H
28 
29 #include <stdint.h>
30 # include <stddef.h>
31 
32 #define container_of(ptr, type, member)                  \
33     ({ const typeof(((type *)0)->member) * __mp = (ptr); \
34        (type *)((char *)__mp - offsetof(type, member)); })
35 
36 #define __COMPILE_ASSERT(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
37 #define _COMPILE_ASSERT(cond) __COMPILE_ASSERT(cond)
38 #define COMPILE_ASSERT(cond) _COMPILE_ASSERT(!!(cond))
39 
40 #ifdef __GNUC__
41 # define check_printf(f, v) __attribute__((format(printf, f, v)))
42 #else
43 # define check_printf(f, v)
44 #endif
45 
46 #endif /* ifndef COMPILER_H */
47