From 1606383a914d21ecc71e13622fae3bf593c8381b Mon Sep 17 00:00:00 2001 From: Sebastian Hack Date: Tue, 31 May 2005 14:19:25 +0000 Subject: [PATCH] Added offset.h [r5928] --- ir/adt/Makefile.in | 2 +- ir/adt/offset.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ir/adt/offset.h diff --git a/ir/adt/Makefile.in b/ir/adt/Makefile.in index 912e45df5..35f03e9b6 100644 --- a/ir/adt/Makefile.in +++ b/ir/adt/Makefile.in @@ -16,7 +16,7 @@ topdir = ../.. subdir := ir/adt disable_libiberty := @disable_libiberty@ -INSTALL_HEADERS_ADT = pset.h set.h pmap.h eset.h hashptr.h array.h pdeq.h iterator.h align.h fourcc.h +INSTALL_HEADERS_ADT = pset.h set.h pmap.h eset.h hashptr.h array.h pdeq.h iterator.h align.h fourcc.h offset.h SOURCES = Makefile.in \ array.c obst.h pdeq.c \ diff --git a/ir/adt/offset.h b/ir/adt/offset.h new file mode 100644 index 000000000..6f797a6b7 --- /dev/null +++ b/ir/adt/offset.h @@ -0,0 +1,34 @@ +/** + * @file offset.h + * @date 31.05.2005 + * @author Sebastian Hack + * + * Firm's own offset_of and container_of + * + * Copyright (C) 2005 Universitaet Karlsruhe + * Released under the GPL + */ + +#ifndef _OFFSET_H +#define _OFFSET_H + +/** + * Get the offset of a member of a struct. + * @param type The type of the struct member is in. + * @param member The name of the member. + * @return The offset of member in type in bytes. + */ +#define offset_of(type, member) \ + ((char *) &(((type *) 0)->member) - (char *) 0) + +/** + * Make pointer to the struct from a pointer to a member of that struct. + * @param ptr The pointer to the member. + * @param type The type of the struct. + * @param member The name of the member. + * @return A pointer to the struct member is in. + */ +#define container_of(ptr, type, member) \ + ((type *) ((char *) (ptr) - offset_of(type, member))) + +#endif /* _OFFSET_H */ -- 2.20.1