X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/763d5e6ad88ef3ba1cd1d7742d060e4f1e54c6b8..d8b957853160200fe6b00d8c0e8c61a3f62ecd7c:/lib/table.h diff --git a/lib/table.h b/lib/table.h index f269ddd..a301db7 100644 --- a/lib/table.h +++ b/lib/table.h @@ -1,6 +1,6 @@ /* * This file is part of DisOrder - * Copyright (C) 2004, 2005 Richard Kettlewell + * Copyright (C) 2004, 2005, 2007, 2008 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 @@ -21,13 +21,15 @@ #ifndef TABLE_H #define TABLE_H -#define TABLE_FIND(TABLE, TYPE, FIELD, NAME) \ - table_find((void *)TABLE, \ - offsetof(TYPE, FIELD), \ - sizeof (TYPE), \ - sizeof TABLE / sizeof (TYPE), \ +#include + +#define TABLE_FIND(TABLE, FIELD, NAME) \ + table_find((void *)TABLE, \ + offsetof(typeof((TABLE)[0]), FIELD), \ + sizeof ((TABLE)[0]), \ + sizeof TABLE / sizeof ((TABLE)[0]), \ NAME) -/* Search TYPE TABLE[] for an element where TABLE[N].FIELD matches NAME +/* Search TABLE[] for an element where TABLE[N].FIELD matches NAME * Returns the index N on success or -1 if not found * The table must be lexically sorted on FIELD */