Reshaped doc's
[fw/sdcc] / doc / sdccman.html / node24.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
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 -->
8 <HTML>
9 <HEAD>
10 <TITLE>3.5 Parameters &amp; Local Variables</TITLE>
11 <META NAME="description" CONTENT="3.5 Parameters &amp; Local Variables">
12 <META NAME="keywords" CONTENT="sdccman">
13 <META NAME="resource-type" CONTENT="document">
14 <META NAME="distribution" CONTENT="global">
15
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">
19
20 <LINK REL="STYLESHEET" HREF="sdccman.css">
21
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">
26 </HEAD>
27
28 <BODY >
29 <!--Navigation Panel-->
30 <A NAME="tex2html612"
31  HREF="node25.html">
32 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
33 <A NAME="tex2html606"
34  HREF="node19.html">
35 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
36 <A NAME="tex2html600"
37  HREF="node23.html">
38 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
39 <A NAME="tex2html608"
40  HREF="node1.html">
41 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
42 <A NAME="tex2html610"
43  HREF="node61.html">
44 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
45 <BR>
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  &nbsp <B>  <A NAME="tex2html609"
53  HREF="node1.html">Contents</A></B> 
54  &nbsp <B>  <A NAME="tex2html611"
55  HREF="node61.html">Index</A></B> 
56 <BR>
57 <BR>
58 <!--End of Navigation Panel-->
59
60 <H2><A NAME="SECTION00045000000000000000">
61 3.5 Parameters &amp; Local Variables</A>
62 </H2>
63
64 <P>
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.
70
71 <P>
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
74 declaration, e.g.:
75 <BR>
76
77 <BR>
78 <TT>unsigned char foo(char i) reentrant </TT>&nbsp;
79 <BR>
80 <TT>{ </TT>&nbsp;
81 <BR>
82 <TT>... </TT>&nbsp;
83 <BR>
84 <TT>}</TT>&nbsp;
85 <BR>
86
87 <BR>
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 &amp; local variables
91 will be allocated to the stack, it <I>does not</I> mean that the function
92 is register bank independent.
93 <BR>
94
95 <BR>
96 Local variables can be assigned storage classes and absolute addresses,
97 e.g.: 
98 <BR>
99
100 <BR>
101 <TT>unsigned char foo() {</TT>&nbsp;
102 <BR>
103 <TT>&nbsp;&nbsp;&nbsp;&nbsp;xdata unsigned char i;</TT>&nbsp;
104 <BR>
105 <TT>&nbsp;&nbsp;&nbsp;&nbsp;bit bvar;</TT>&nbsp;
106 <BR>
107 <TT>&nbsp;&nbsp;&nbsp;&nbsp;data at 0x31 unsiged char j;</TT>&nbsp;
108 <BR>
109 <TT>&nbsp;&nbsp;&nbsp;&nbsp;... </TT>&nbsp;
110 <BR>
111 <TT>}</TT>&nbsp;
112 <BR>&nbsp;
113 <BR>
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.
118
119 <P>
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.
123
124 <P>
125 <HR>
126 <!--Navigation Panel-->
127 <A NAME="tex2html612"
128  HREF="node25.html">
129 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
130 <A NAME="tex2html606"
131  HREF="node19.html">
132 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
133 <A NAME="tex2html600"
134  HREF="node23.html">
135 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
136 <A NAME="tex2html608"
137  HREF="node1.html">
138 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
139 <A NAME="tex2html610"
140  HREF="node61.html">
141 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
142 <BR>
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  &nbsp <B>  <A NAME="tex2html609"
150  HREF="node1.html">Contents</A></B> 
151  &nbsp <B>  <A NAME="tex2html611"
152  HREF="node61.html">Index</A></B> 
153 <!--End of Navigation Panel-->
154 <ADDRESS>
155 <I>Johan Knol</I>
156 <BR><I>2001-07-13</I>
157 </ADDRESS>
158 </BODY>
159 </HTML>