<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> {The S-lang C Library Reference}: SLclass_set_destroy_function</TITLE>
<LINK HREF="cref-44.html" REL=next>
<LINK HREF="cref-42.html" REL=previous>
<LINK HREF="cref.html#toc43" REL=contents>
</HEAD>
<BODY>
<A HREF="cref-44.html">Next</A>
<A HREF="cref-42.html">Previous</A>
<A HREF="cref.html#toc43">Contents</A>
<HR>
<H2><A NAME="SLclass_set_destroy_function"></A> <A NAME="s43">43. <B>SLclass_set_destroy_function</B></A></H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Set the destroy method callback for a data type
<DT><B> Usage </B><DD><P><CODE>int SLclass_set_destroy_function (cl, destroy_fun)</CODE>
<BLOCKQUOTE><CODE>
<PRE>
    SLang_Class_Type *cl
    void (*destroy_fun) (unsigned char, VOID_STAR);
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> Description </B><DD><P><CODE>SLclass_set_destroy_function</CODE> is used to set the destroy
callback for a data type.  The data type's class <CODE>cl</CODE> must have
been previously obtained via a call to <CODE>SLclass_allocate_class</CODE>.
When called, <CODE>destroy_fun</CODE> will be passed two arguments: a
unsigned char which represents the data type, and the address of the
object to be destroyed.
<P><CODE>SLclass_set_destroy_function</CODE> returns zero upon success, and
<CODE>-1</CODE> upon failure.
<DT><B> Example </B><DD><P>The destroy method for <CODE>SLANG_STRING_TYPE</CODE> looks like:
<BLOCKQUOTE><CODE>
<PRE>
    static void string_destroy (unsigned char type, VOID_STAR ptr)
    {
       char *s = *(char **) ptr;
       if (s != NULL) SLang_free_slstring (*(char **) s);
    }
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> Notes </B><DD><P>Data types of class SLANG_CLASS_TYPE_SCALAR do not require a destroy
callback.  However, other classes do.
<DT><B> See Also </B><DD><P><CODE>SLclass_allocate_class, SLclass_register_class</CODE>
</DL>
<P>
<P>
<P>
<HR>
<A HREF="cref-44.html">Next</A>
<A HREF="cref-42.html">Previous</A>
<A HREF="cref.html#toc43">Contents</A>
</BODY>
</HTML>
