Common lisp 如何在sbcl中查找外来结构的大小?

Common lisp 如何在sbcl中查找外来结构的大小?,common-lisp,ffi,sbcl,Common Lisp,Ffi,Sbcl,我试图在SBCL中获得外来结构的大小(为外来函数生成适当大小的数据缓冲区)。在C或Pascal sizeof()中,执行相同的工作。我的做法是: (define-alien-type MY-STRUCT (struct MY-STRUCT (MY-FIELD (array char 30)))) (defmacro size-of (type) (let ((x (gensym))) `(let ((,x (make-alien (array ,typ

我试图在SBCL中获得外来结构的大小(为外来函数生成适当大小的数据缓冲区)。在C或Pascal sizeof()中,执行相同的工作。我的做法是:

(define-alien-type MY-STRUCT
(struct MY-STRUCT
        (MY-FIELD (array char 30))))

(defmacro size-of (type) 
    (let ((x (gensym)))
        `(let ((,x (make-alien (array ,type 2))))
             (- (sb-sys:sap-int (alien-sap (deref (deref ,x) 1)))
                (sb-sys:sap-int (alien-sap (deref (deref ,x) 0)))))))

(size-of MY-STRUCT) ;; => 30

在SBCL中是否有适当的方法获取外来结构的大小?

(外来结构的大小:字节)
应该可以。@jkiiski,谢谢!(有效)