mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-27 08:10:07 +08:00
Define and use offsetin() instead of offsetof()
New macro which defines the offset on an object rather than a type. This macro, as far as I know, ought to be fully portable, unlike the fallback version of offsetof(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
parent
374312cde4
commit
ce19a52a34
@ -180,6 +180,13 @@ typedef enum bool { false, true } bool;
|
||||
# define offsetof(t,m) ((size_t)&(((t *)0)->m))
|
||||
#endif
|
||||
|
||||
/* This is like offsetof(), but takes an object rather than a type.
|
||||
Ironically enough this is actually guaranteed to be portable,
|
||||
as far as I know... */
|
||||
#ifndef offsetin
|
||||
# define offsetin(p,m) ((const char *)&((p).m) - (const char *)&(p))
|
||||
#endif
|
||||
|
||||
/* The container_of construct: if p is a pointer to member m of
|
||||
container class c, then return a pointer to the container of which
|
||||
*p is a member. */
|
||||
|
@ -108,7 +108,7 @@ strlist_vprintf(struct strlist *list, const char *fmt, va_list ap)
|
||||
if (!list)
|
||||
return NULL;
|
||||
|
||||
e = nasm_vaxprintf(offsetof(struct strlist_entry, str), fmt, ap);
|
||||
e = nasm_vaxprintf(offsetin(*e, str), fmt, ap);
|
||||
e->size = nasm_aprintf_size();
|
||||
|
||||
if (list->uniq) {
|
||||
|
Loading…
Reference in New Issue
Block a user