| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef _BABELTRACE_COMPILER_H |
| 8 | #define _BABELTRACE_COMPILER_H |
| 9 | |
| 10 | #include <stddef.h> /* for offsetof */ |
| 11 | |
| 12 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) |
| 13 | |
| 14 | #ifndef container_of |
| 15 | #define container_of(ptr, type, member) \ |
| 16 | ({ \ |
| 17 | const typeof(((type *)NULL)->member) * __ptr = (ptr); \ |
| 18 | (type *)((char *)__ptr - offsetof(type, member)); \ |
| 19 | }) |
| 20 | #endif |
| 21 | |
| 22 | #define BT_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 23 | |
| 24 | #endif /* _BABELTRACE_COMPILER_H */ |