1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3 <!--Converted with LaTeX2HTML 99.1 release (March 30, 1999)
4 original version by: Nikos Drakos, CBLU, University of Leeds
5 * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
6 * with significant contributions from:
7 Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
10 <TITLE>3.5 Parameters & Local Variables</TITLE>
11 <META NAME="description" CONTENT="3.5 Parameters & Local Variables">
12 <META NAME="keywords" CONTENT="sdccman">
13 <META NAME="resource-type" CONTENT="document">
14 <META NAME="distribution" CONTENT="global">
16 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
17 <META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
18 <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
20 <LINK REL="STYLESHEET" HREF="sdccman.css">
22 <LINK REL="next" HREF="node25.html">
23 <LINK REL="previous" HREF="node23.html">
24 <LINK REL="up" HREF="node19.html">
25 <LINK REL="next" HREF="node25.html">
29 <!--Navigation Panel-->
32 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
35 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
38 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
41 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
44 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
46 <B> Next:</B> <A NAME="tex2html613"
47 HREF="node25.html">3.6 Overlaying</A>
48 <B> Up:</B> <A NAME="tex2html607"
49 HREF="node19.html">3. Using SDCC</A>
50 <B> Previous:</B> <A NAME="tex2html601"
51 HREF="node23.html">3.4 Pointers</A>
52   <B> <A NAME="tex2html609"
53 HREF="node1.html">Contents</A></B>
54   <B> <A NAME="tex2html611"
55 HREF="node61.html">Index</A></B>
58 <!--End of Navigation Panel-->
60 <H2><A NAME="SECTION00045000000000000000">
61 3.5 Parameters & Local Variables</A>
65 Automatic (local) variables and parameters to functions can either
66 be placed on the stack or in data-space. The default action of the
67 compiler is to place these variables in the internal RAM (for small
68 model) or external RAM (for Large model). This in fact makes them
69 <I>static</I> so by default functions are non-reentrant.
72 They can be placed on the stack either by using the <I>-stack-auto</I>
73 compiler option or by using the <I>reentrant</I> keyword in the function
78 <TT>unsigned char foo(char i) reentrant </TT>
88 Since stack space on 8051 is limited, the <I>reentrant</I> keyword
89 or the <I>-stack-auto</I> option should be used sparingly. Note that
90 the reentrant keyword just means that the parameters & local variables
91 will be allocated to the stack, it <I>does not</I> mean that the function
92 is register bank independent.
96 Local variables can be assigned storage classes and absolute addresses,
101 <TT>unsigned char foo() {</TT>
103 <TT> xdata unsigned char i;</TT>
105 <TT> bit bvar;</TT>
107 <TT> data at 0x31 unsiged char j;</TT>
109 <TT> ... </TT>
114 In the above example the variable <I>i</I> will be allocated in the
115 external ram, <I>bvar</I> in bit addressable space and <I>j</I> in
116 internal ram. When compiled with <I>-stack-auto</I> or when a function
117 is declared as <I>reentrant</I> this can only be done for static variables.
120 Parameters however are not allowed any storage class, (storage classes
121 for parameters will be ignored), their allocation is governed by the
122 memory model in use, and the reentrancy options.
126 <!--Navigation Panel-->
127 <A NAME="tex2html612"
129 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
130 <A NAME="tex2html606"
132 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
133 <A NAME="tex2html600"
135 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
136 <A NAME="tex2html608"
138 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
139 <A NAME="tex2html610"
141 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
143 <B> Next:</B> <A NAME="tex2html613"
144 HREF="node25.html">3.6 Overlaying</A>
145 <B> Up:</B> <A NAME="tex2html607"
146 HREF="node19.html">3. Using SDCC</A>
147 <B> Previous:</B> <A NAME="tex2html601"
148 HREF="node23.html">3.4 Pointers</A>
149   <B> <A NAME="tex2html609"
150 HREF="node1.html">Contents</A></B>
151   <B> <A NAME="tex2html611"
152 HREF="node61.html">Index</A></B>
153 <!--End of Navigation Panel-->
156 <BR><I>2001-07-13</I>