/* PSPP - a program for statistical analysis.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2009, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
+#include "libpspp/cast.h"
/* Embedded, circular doubly linked list.
/* Returns the data structure corresponding to the given node LL,
assuming that LL is embedded as the given MEMBER name in data
type STRUCT. */
-#define ll_data(LL, STRUCT, MEMBER) \
- ((STRUCT *) ((char *) (LL) - offsetof (STRUCT, MEMBER)))
+#define ll_data(LL, STRUCT, MEMBER) \
+ (CHECK_POINTER_HAS_TYPE(LL, struct ll *), \
+ UP_CAST(LL, STRUCT, MEMBER))
/* Linked list node. */
struct ll
#define ll_tail__(STRUCT, MEMBER, LIST) \
ll_data__ (ll_tail (LIST), STRUCT, MEMBER, LIST)
#define ll_next__(DATA, STRUCT, MEMBER, LIST) \
- ll_data__ (ll_next (&DATA->MEMBER), STRUCT, MEMBER, LIST)
+ ll_data__ (ll_next (&(DATA)->MEMBER), STRUCT, MEMBER, LIST)
#define ll_prev__(DATA, STRUCT, MEMBER, LIST) \
- ll_data__ (ll_prev (&DATA->MEMBER), STRUCT, MEMBER, LIST)
+ ll_data__ (ll_prev (&(DATA)->MEMBER), STRUCT, MEMBER, LIST)
\f
/* Inline functions. */
static inline struct ll *
ll_null (const struct ll_list *list)
{
- return (struct ll *) &list->null;
+ return CONST_CAST (struct ll *, &list->null);
}
/* Returns the node following LL in its list,