Sophie

Sophie

distrib > Mandriva > 8.1 > i586 > by-pkgid > 700475c8ae73fb4d57b6df4485c29e1c > files > 35

slang-doc-1.4.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE> {The S-lang C Library Reference}: SLadd_intrinsic_variable</TITLE>
 <LINK HREF="cref-103.html" REL=next>
 <LINK HREF="cref-101.html" REL=previous>
 <LINK HREF="cref.html#toc102" REL=contents>
</HEAD>
<BODY>
<A HREF="cref-103.html">Next</A>
<A HREF="cref-101.html">Previous</A>
<A HREF="cref.html#toc102">Contents</A>
<HR>
<H2><A NAME="SLadd_intrinsic_variable"></A> <A NAME="s102">102. <B>SLadd_intrinsic_variable</B></A></H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Add an intrinsic variable to the interpreter
<DT><B> Usage </B><DD><P><CODE>int SLadd_intrinsic_variable (name, addr, type, rdonly)</CODE>
<BLOCKQUOTE><CODE>
<PRE>
    char *name
    VOID_STAR type
    unsigned char type
    int rdonly
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> Description </B><DD><P>The <CODE>SLadd_intrinsic_variable</CODE> function adds an intrinsic
variable called <CODE>name</CODE> to the interpeter.  The second parameter
<CODE>addr</CODE> specifies the address of the variable (cast to
<CODE>VOID_STAR</CODE>).  The third parameter, <CODE>type</CODE>, specifies the
data type of the variable.  If the fourth parameter, <CODE>rdonly</CODE>,
is non-zero, the variable will interpreted by the interpreter as
read-only.
<P>If successful, <CODE>SLadd_intrinsic_variable</CODE> returns zero,
otherwise it returns <CODE>-1</CODE>.
<DT><B> Example </B><DD><P>Suppose that <CODE>My_Global_Int</CODE> is a global variable (at least not
a local one):
<BLOCKQUOTE><CODE>
<PRE>
    int My_Global_Int;
</PRE>
</CODE></BLOCKQUOTE>

It can be added to the interpreter via the function call
<BLOCKQUOTE><CODE>
<PRE>
    if (-1 == SLadd_intrinsic_variable ("MyGlobalInt",
                                        (VOID_STAR)&amp;My_Global_Int,
                                        SLANG_INT_TYPE, 0))
      exit (1);
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> Notes </B><DD><P>The current implementation requires all pointer type intrinsic
variables to be read-only.  For example,
<BLOCKQUOTE><CODE>
<PRE>
    char *My_Global_String;
</PRE>
</CODE></BLOCKQUOTE>

is of type <CODE>SLANG_STRING_TYPE</CODE>, and must be declared as
read-only.  Finally, not that
<BLOCKQUOTE><CODE>
<PRE>
   char My_Global_Char_Buf[256];
</PRE>
</CODE></BLOCKQUOTE>

is <EM>not</EM> a <CODE>SLANG_STRING_TYPE</CODE> object.  This difference is
very important because internally the interpreter dereferences the
address passed to it to get to the value of the variable.
<DT><B> See Also </B><DD><P><CODE>SLadd_intrinsic_function, SLadd_intrinsic_array</CODE>
</DL>
<P>}
<P>
<P>
<HR>
<A HREF="cref-103.html">Next</A>
<A HREF="cref-101.html">Previous</A>
<A HREF="cref.html#toc102">Contents</A>
</BODY>
</HTML>