diff --git a/grovel/common.h b/grovel/common.h index 4ea2aac99e486e726af65edd7dd550de002c227d..b44b0c24a78e90254e57e91a8b545d4cce36d02e 100644 --- a/grovel/common.h +++ b/grovel/common.h @@ -7,7 +7,10 @@ #ifndef offsetof #define offsetof(type, slot) ((long) ((char *) &(((type *) 0)->slot))) #endif -#define sizeofslot(type, slot) (sizeof(((type *) 0)->slot)) +#define getslot(type, slot) (((type *) 0)->slot) +#define sizeofslot(type, slot) (sizeof(getslot(type, slot))) +#define countofslot(type, slot) \ + (sizeof(getslot(type, slot)) / sizeof(getslot(type, slot)[0])) #define stringify(x) #x #define indirect_stringify(x) stringify(x) diff --git a/grovel/grovel.lisp b/grovel/grovel.lisp index 62cf04633ec2a2aed985e82e99b953885a0adcb7..b7d2579ba29cbddb90580af5f62e989c3364978c 100644 --- a/grovel/grovel.lisp +++ b/grovel/grovel.lisp @@ -501,8 +501,7 @@ int main(int argc, char**argv) { (c-format out " :count ~D" count)) ((eql :auto) (c-printf out " :count %i" - (format nil "sizeof(~A) - offsetof(~A, ~A)" - struct-c-name + (format nil "countofslot(~A, ~A)" struct-c-name slot-c-name))) ((or symbol string)