Use __typeof__ instead of typeof
[babeltrace.git] / src / compat / compiler.h
CommitLineData
ccd7e1c8 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
ccd7e1c8 3 *
0235b0db 4 * Copyright 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ccd7e1c8
MD
5 */
6
0235b0db
MJ
7#ifndef _BABELTRACE_COMPILER_H
8#define _BABELTRACE_COMPILER_H
9
334c0a83
MD
10#include <stddef.h> /* for offsetof */
11
d79865b9
MD
12#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
13
fc93b2bd
MD
14#ifndef container_of
15#define container_of(ptr, type, member) \
16 ({ \
0ec1ae8b 17 const __typeof__(((type *)NULL)->member) * __ptr = (ptr); \
fc93b2bd
MD
18 (type *)((char *)__ptr - offsetof(type, member)); \
19 })
20#endif
21
6e1bc0df
MD
22#define BT_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
23
d79865b9 24#endif /* _BABELTRACE_COMPILER_H */
This page took 0.083387 seconds and 4 git commands to generate.