From: Michael Brown Date: Mon, 26 Jul 2010 12:26:34 +0000 (+0100) Subject: [tables] Add table_index() X-Git-Tag: v1.20.1~2554 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da123eada44c19a2b4efd2e095b3f90313dffd69;p=thirdparty%2Fipxe.git [tables] Add table_index() Signed-off-by: Michael Brown --- diff --git a/src/include/ipxe/tables.h b/src/include/ipxe/tables.h index 130486c67..74d437537 100644 --- a/src/include/ipxe/tables.h +++ b/src/include/ipxe/tables.h @@ -308,6 +308,31 @@ FILE_LICENCE ( GPL2_OR_LATER ); ( ( unsigned int ) ( table_end ( table ) - \ table_start ( table ) ) ) +/** + * Get index of entry within linker table + * + * @v table Linker table + * @v entry Table entry + * + * Example usage: + * + * @code + * + * #define FROBNICATORS __table ( struct frobnicator, "frobnicators" ) + * + * #define __frobnicator __table_entry ( FROBNICATORS, 01 ) + * + * struct frobnicator my_frob __frobnicator = { + * ... + * }; + * + * unsigned int my_frob_idx = table_index ( FROBNICATORS, &my_frob ); + * + * @endcode + */ +#define table_index( table, entry ) \ + ( ( unsigned int ) ( (entry) - table_start ( table ) ) ) + /** * Iterate through all entries within a linker table *