[Ecls-list] (and defconstant ffi:c-inline)
mm_lists at pulsar-zone.net
Fri Apr 2 03:29:37 UTC 2010
I noticed that when using a constuct such as the following:
(defconstant +foo+ 'bar))
(defun baz ()
The compiler generates a warning when compiling BAZ about +FOO+ being
unknown and assuming a global, whereas:
(defconstant +foo+ 'bar)
(defun baz ()
Generates no such warning and the resulting code is indeed better
optimized, where the constant values can really be used inline instead
of looking up the global. This is fine; although when using
FFI:C-INLINE to refer to C constants it appears impossible to use
outside of a similar block:
(defconstant +o-rdonly+ (ffi:c-inline () () :int "O_RDONLY" :one-liner t))
At compile time the following error occurs:
;;; The special form c-inline cannot be used in the interpreter: (NIL NIL INT O_RDONLY ONE-LINER T)
(eval-when (:compile-toplevel :load-toplevel :execute)
(eval-when (:compile-toplevel :load-toplevel)
(ffi:c-inline () () :int "O_RDONLY" :one-liner t))))
Compiles and loads fine, but then +O-RDONLY+ is NIL.
(ffi:c-inline () () :int "O_RDONLY" :one-liner t)))
Then works fine, but unfortunately the same warning as above using LET
occurs, and the code must also look up for globals.
Any suggestion or trick which would allow to define CL constant
litterals deriving from a C constant, which would not have to lookup
globals, so that I could fix my DEFINE-C-CONSTANTS macro to use it?
I admit being relatively new to the various CL environments and could
very well be missing something obvious.
More information about the ecl-devel