22 lines
684 B
C
22 lines
684 B
C
#ifndef PLUGIN_OFFSETOF_H
|
|
#define PLUGIN_OFFSETOF_H
|
|
|
|
#include <stddef.h> /* defines offsetof to be __builtin_offsetof */
|
|
|
|
__attribute__((const, noinline))
|
|
static size_t __spslr_offsetof(const char *t, const char *m, size_t v) {
|
|
/* never executed; replaced by plugin */
|
|
(void)t; (void)m; (void)v;
|
|
return v;
|
|
}
|
|
|
|
/*
|
|
Replace __builtin_offsetof with encoding of type and member that survives C frontend
|
|
Macro recursion prevention leaves the inner __builtin_offsetof there, otherwise use "(((size_t)&((T*)0)->M))"
|
|
*/
|
|
#undef __builtin_offsetof
|
|
#define __builtin_offsetof(T,M) \
|
|
((size_t (*)(const char*, const char*, size_t))__spslr_offsetof)((#T), (#M), __builtin_offsetof(T,M))
|
|
|
|
#endif
|