Spiros Bousbouras <
spi...@gmail.com> writes:
> The CLHS page for INLINE and NOTINLINE say that a compiler "is free to
> ignore" INLINE but "is not free to ignore" NOTINLINE .Why is that ?
It is a programming thing. I usually use it with interfaces so that if
the code changes any dependent software will not have to be recompiled.
Ex...
;;;; Termcap Interface
(declaim (notinline tgetstr tgetnum tgetstr))
(defun tgetflag (cap)
"Return value of termcap boolean capability <CAP>."
(declare (type simple-string cap))
(get-sequence cap))
(defun tgetnum (cap)
"Return value of boolean capability <CAP>."
(declare (type simple-string cap))
(get-sequence cap))
(defun tgetstr (cap)
"Return a string for capability <CAP>."
(declare (type simple-string cap))
(get-sequence cap))
If these functions where inlined then every time I recompile the file,
the entire program must be recompiled. This is similar to static
libraries vs. dynamic libraries. On unix that would be `.a' and `.so' .
On windows it would be a DLL.
I think most people can agree that static libraries can lead to some
very agrevating problems.
> Are there
> some things which are guaranteed to work if a function has been declared
> NOTINLINE but may or may not work otherwise ?
When debugging code :)
Seriousy, gcc has this problem like nothing else. When compiling with
GCC if you want to debug use -ggdb and an optimization of -Og.
This is a new feature - a very good one, like -fverbose-asm.
> declarations for the following functions , is the following guaranteed to
> work as appears in the output below ?
>
> ==============
> * (defun foo1 () 'foo1)
>
> FOO1
> * (defun foo2 () 'foo2)
>
> FOO2
> * (defun foo3 () 'foo3)
>
> FOO3
> * (foo3)
>
> FOO3
> * (setf (symbol-function 'foo3) (function foo1))
No. I believe you are misunderstanding symbol-function. Symbol-function
is like using the C preprocessor but at run time.
;;;; Globals and symbol-macros
(defstruct (screen (:copier nil) :named)
(namestring "Standard Screen" :type simple-string :read-only t)
;; [ ... ]
;; cursor position movement
(cur-x 0 :type (unsigned-byte 16))
(cur-y 0 :type (unsigned-byte 16))
(max-x 0 :type (unsigned-byte 16))
(max-y 0 :type (unsigned-byte 16)))
(defvar *current-screen* (make-screen)
"The current screen object.")
(defun current-screen ()
"Return the current screen object. This function is never called directly."
(the screen *current-screen*))
(define-symbol-macro *LINES* (screen-max-x (current-screen)))
;; "Number of rows for the current screen."
(define-symbol-macro *COLUMNS* (screen-max-y (current-screen)))
;; "Number of columns for the current screen."
The symbol-macro *COLUMNS* can be used like a global variable, but the
value is computed at runtime. Very cool feature.
> #<FUNCTION FOO1>
> * (foo3)
>
> FOO1
> * (setf (symbol-function 'foo3) (function foo2))
>
> #<FUNCTION FOO2>
> * (foo3)
>
> FOO2
> ==============
>
> Might any declarations of INLINE affect the output ?
When do you need the values? At runtime or compile time? I try not to
ever use global variables - I love the symbol-macro.
hope this helps some. if not please just ask away...