From 3fc75114f93094024e457141d8e67cda38b87e9b Mon Sep 17 00:00:00 2001 Message-Id: <3fc75114f93094024e457141d8e67cda38b87e9b.1715290055.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 17 Nov 2013 11:34:18 +0000 Subject: [PATCH] table search: cope without typeof Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/table.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/table.h b/lib/table.h index db237ac..0694fd3 100644 --- a/lib/table.h +++ b/lib/table.h @@ -1,6 +1,6 @@ /* * This file is part of DisOrder - * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell + * Copyright (C) 2004, 2005, 2007, 2008, 2013 Richard Kettlewell * * 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 @@ -23,9 +23,15 @@ #include +#if _WIN32 +#define OFFSETOF_IN_OBJECT(OBJECT,FIELD) ((char *)&(OBJECT).FIELD - (char *)&(OBJECT)) +#else +#define OFFSETOF_IN_OBJECT(OBJECT,FIELD) offsetof(typeof(OBJECT),FIELD) +#endif + #define TABLE_FIND(TABLE, FIELD, NAME) \ table_find((void *)TABLE, \ - offsetof(typeof((TABLE)[0]), FIELD), \ + OFFSETOF_IN_OBJECT(TABLE[0], FIELD), \ sizeof ((TABLE)[0]), \ sizeof TABLE / sizeof ((TABLE)[0]), \ NAME) -- [mdw]