Skip to content

lisp側のdefcstructで,byte, short, int型以外の型を定義する必要があると思うのですが,そのようなことは可能なのでしょうか? #460

Open
@k-okada

Description

@k-okada

解決したか解決していないのかわからなかったのですが,
defcstruct では型を定義する必要はなくて,ポインタの長さを書けば良いんだと思います.
難しいのは,コンパイルしたときに構造体の要素の置かれる位置がバイト境界になることで,
コンパイラオプション等々に依存することです.

やりたいこととのCサンプルプログラム(構造体を定義して,構造体受け取って中身を表示する関数?)
があるとLisp側のサンプルプログラムが作れると思います.

;; typedef struct {
;; int type; /* of event */
;; unsigned long serial; /* # of last request processed by server */
;; Bool send_event; /* true if this came from a SendEvent request */
;; Display *display; /* Display the event was read from */
;; Window window; /* "event" window reported relative to */
;; Window root; /* root window that the event occurred on */
;; Window subwindow; /* child window */
;; Time time; /* milliseconds */
;; int x, y; /* pointer x, y coordinates in event window */
;; int x_root, y_root; /* coordinates relative to root */
;; unsigned int state; /* key or button mask */
;; char is_hint; /* detail */
;; Bool same_screen; /* same screen flag */
;; } XMotionEvent;
;;; event processing
(defcstruct XEvent
(type :integer) ;0
(serial :long) ;1
(send-event :integer) ;2
(display :long) ;3
(window :long) ;4
(root :long) ;5
(subwindow :long) ;6
#-:alpha
(time :long) ;7
#+:alpha
(time :integer) ;7
(x :integer) ;8
(y :integer) ;9
(x-root :integer) ;10
(y-root :integer) ;11
(state :integer) ;12
(detail :integer) ;13
(same-screen :integer) ;14
(focus :integer) ;15
(alt-state :integer) ;16
#-(or :alpha :irix6 :word-size=64)
(pad :char 28) ;xevent is required to hold 24 longs
#+:irix6
(pad :char 84)
#+:alpha
(pad :char 88)
#+(or :word-size=64)
(pad :char 92) ;xevent is required to hold xx longs at x86-64
)

@chibi314, @inabajsk

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions