84 lines
9 KiB
HTML
84 lines
9 KiB
HTML
|
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
||
|
<HTML>
|
||
|
<HEAD>
|
||
|
<TITLE>CLHS: Declaration INLINE, NOTINLINE</TITLE>
|
||
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
||
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
||
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
||
|
<LINK REL=TOP HREF="../Front/index.htm">
|
||
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
||
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
||
|
<LINK REL=PREV HREF="d_type.htm">
|
||
|
<LINK REL=UP HREF="c_evalua.htm">
|
||
|
<LINK REL=NEXT HREF="d_ftype.htm">
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="d_type.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_evalua.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="d_ftype.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
||
|
|
||
|
<HR>
|
||
|
|
||
|
<A NAME="inline"><A NAME="notinline"><I>Declaration</I> <B>INLINE, NOTINLINE</B></A></A> <P>
|
||
|
<P><B>Syntax:</B><P>
|
||
|
<P>
|
||
|
<TT>(inline </TT><I>function-name</I><TT></TT><B>*</B><TT>)</TT> <P>
|
||
|
<TT>(notinline </TT><I>function-name</I><TT></TT><B>*</B><TT>)</TT> <P>
|
||
|
<P><B>Arguments:</B><P>
|
||
|
<P>
|
||
|
<I>function-name</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A>. <P>
|
||
|
<P><B>Valid Context:</B><P>
|
||
|
<P>
|
||
|
<A REL=DEFINITION HREF="26_glo_d.htm#declaration"><I>declaration</I></A> or <A REL=DEFINITION HREF="26_glo_p.htm#proclamation"><I>proclamation</I></A> <P>
|
||
|
<P><B>Binding Types Affected:</B><P>
|
||
|
<P>
|
||
|
<A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <P>
|
||
|
<P><B>Description:</B><P>
|
||
|
<P>
|
||
|
<A REL=DEFINITION HREF="#inline"><B>inline</B></A> specifies that it is desirable for the compiler to produce inline calls to the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>functions</I></A> named by <I>function-names</I>; that is, the code for a specified <I>function-name</I> should be integrated into the calling routine, appearing ``in line'' in place of a procedure call. A compiler is free to ignore this declaration. <A REL=DEFINITION HREF="#inline"><B>inline</B></A> declarations never apply to variable <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>bindings</I></A>. <P>
|
||
|
If one of the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>functions</I></A> mentioned has a lexically apparent local definition (as made by <A REL=DEFINITION HREF="s_flet_.htm#flet"><B>flet</B></A> or <A REL=DEFINITION HREF="s_flet_.htm#labels"><B>labels</B></A>), then the declaration applies to that local definition and not to the global function definition. <P>
|
||
|
While no <A REL=DEFINITION HREF="26_glo_c.htm#conforming_implementation"><I>conforming implementation</I></A> is required to perform inline expansion of user-defined functions, those <A REL=DEFINITION HREF="26_glo_i.htm#implementation"><I>implementations</I></A> that do attempt to recognize the following paradigm: <P>
|
||
|
To define a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <TT>f</TT> that is not <A REL=DEFINITION HREF="#inline"><B>inline</B></A> by default but for which <TT>(declare (inline f))</TT> will make <I>f</I> be locally inlined, the proper definition sequence is: <P>
|
||
|
<PRE>
|
||
|
(declaim (inline f))
|
||
|
(defun f ...)
|
||
|
(declaim (notinline f))
|
||
|
</PRE>
|
||
|
</TT> <P>
|
||
|
The <A REL=DEFINITION HREF="#inline"><B>inline</B></A> proclamation preceding the <A REL=DEFINITION HREF="m_defun.htm#defun"><B>defun</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> ensures that the <A REL=DEFINITION HREF="26_glo_c.htm#compiler"><I>compiler</I></A> has the opportunity save the information necessary for inline expansion, and the <A REL=DEFINITION HREF="#notinline"><B>notinline</B></A> proclamation following the <A REL=DEFINITION HREF="m_defun.htm#defun"><B>defun</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> prevents <TT>f</TT> from being expanded inline everywhere. <P>
|
||
|
<A REL=DEFINITION HREF="#notinline"><B>notinline</B></A> specifies that it is undesirable to compile the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>functions</I></A> named by <I>function-names</I> in-line. A compiler is not free to ignore this declaration; calls to the specified functions must be implemented as out-of-line subroutine calls. <P>
|
||
|
If one of the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>functions</I></A> mentioned has a lexically apparent local definition (as made by <A REL=DEFINITION HREF="s_flet_.htm#flet"><B>flet</B></A> or <A REL=DEFINITION HREF="s_flet_.htm#labels"><B>labels</B></A>), then the declaration applies to that local definition and not to the global function definition. <P>
|
||
|
In the presence of a <A REL=DEFINITION HREF="26_glo_c.htm#compiler_macro"><I>compiler macro</I></A> definition for <I>function-name</I>, a <A REL=DEFINITION HREF="#notinline"><B>notinline</B></A> declaration prevents that <A REL=DEFINITION HREF="26_glo_c.htm#compiler_macro"><I>compiler macro</I></A> from being used. An <A REL=DEFINITION HREF="#inline"><B>inline</B></A> declaration may be used to encourage use of <A REL=DEFINITION HREF="26_glo_c.htm#compiler_macro"><I>compiler macro</I></A> definitions. <A REL=DEFINITION HREF="#inline"><B>inline</B></A> and <A REL=DEFINITION HREF="#notinline"><B>notinline</B></A> declarations otherwise have no effect when the lexically visible definition of <I>function-name</I> is a <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A> definition. <P>
|
||
|
<A REL=DEFINITION HREF="#inline"><B>inline</B></A> and <A REL=DEFINITION HREF="#notinline"><B>notinline</B></A> declarations can be <A REL=DEFINITION HREF="26_glo_f.htm#free_declaration"><I>free declarations</I></A> or <A REL=DEFINITION HREF="26_glo_b.htm#bound_declaration"><I>bound declarations</I></A>. <A REL=DEFINITION HREF="#inline"><B>inline</B></A> and <A REL=DEFINITION HREF="#notinline"><B>notinline</B></A> declarations of functions that appear before the body of a <A REL=DEFINITION HREF="s_flet_.htm#flet"><B>flet</B></A> or <A REL=DEFINITION HREF="s_flet_.htm#labels"><B>labels</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> that defines that function are <A REL=DEFINITION HREF="26_glo_b.htm#bound_declaration"><I>bound declarations</I></A>. Such declarations in other contexts are <A REL=DEFINITION HREF="26_glo_f.htm#free_declaration"><I>free declarations</I></A>. <P>
|
||
|
<P><B>Examples:</B><P>
|
||
|
<P>
|
||
|
<PRE>
|
||
|
;; The globally defined function DISPATCH should be open-coded,
|
||
|
;; if the implementation supports inlining, unless a NOTINLINE
|
||
|
;; declaration overrides this effect.
|
||
|
(declaim (inline dispatch))
|
||
|
(defun dispatch (x) (funcall (get (car x) 'dispatch) x))
|
||
|
;; Here is an example where inlining would be encouraged.
|
||
|
(defun top-level-1 () (dispatch (read-command)))
|
||
|
;; Here is an example where inlining would be prohibited.
|
||
|
(defun top-level-2 ()
|
||
|
(declare (notinline dispatch))
|
||
|
(dispatch (read-command)))
|
||
|
;; Here is an example where inlining would be prohibited.
|
||
|
(declaim (notinline dispatch))
|
||
|
(defun top-level-3 () (dispatch (read-command)))
|
||
|
;; Here is an example where inlining would be encouraged.
|
||
|
(defun top-level-4 ()
|
||
|
(declare (inline dispatch))
|
||
|
(dispatch (read-command)))
|
||
|
</PRE>
|
||
|
</TT> <P>
|
||
|
<P><B>See Also:</B><P>
|
||
|
<P>
|
||
|
<A REL=DEFINITION HREF="s_declar.htm#declare"><B>declare</B></A>, <A REL=DEFINITION HREF="m_declai.htm#declaim"><B>declaim</B></A>, <A REL=DEFINITION HREF="f_procla.htm#proclaim"><B>proclaim</B></A> <P>
|
||
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss181.htm">GENERIC-FLET-POORLY-DESIGNED:DELETE</A><LI> <A REL=CHILD HREF="../Issues/iss359.htm">WITH-ADDED-METHODS:DELETE</A><LI> <A REL=CHILD HREF="../Issues/iss228.htm">MACRO-DECLARATIONS:MAKE-EXPLICIT</A><LI> <A REL=CHILD HREF="../Issues/iss007.htm">ALLOW-LOCAL-INLINE:INLINE-NOTINLINE</A><LI> <A REL=CHILD HREF="../Issues/iss174.htm">FUNCTION-NAME:LARGE</A><P></UL><HR>
|
||
|
|
||
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
||
|
|
||
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
||
|
</BODY>
|
||
|
</HTML>
|