beacca595f9ea3217528efe6bcdcd91371e7776d
[fw/sdcc] / doc / SDCCUdoc-7.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4  <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
5  <TITLE>SDCC Compiler User Guide: Pointers</TITLE>
6  <LINK HREF="SDCCUdoc-8.html" REL=next>
7  <LINK HREF="SDCCUdoc-6.html" REL=previous>
8  <LINK HREF="SDCCUdoc.html#toc7" REL=contents>
9 </HEAD>
10 <BODY>
11 <A HREF="SDCCUdoc-8.html">Next</A>
12 <A HREF="SDCCUdoc-6.html">Previous</A>
13 <A HREF="SDCCUdoc.html#toc7">Contents</A>
14 <HR>
15 <H2><A NAME="Pointers"></A> <A NAME="s7">7. Pointers</A> </H2>
16
17 <P>SDCC allows (via language extensions) pointers to explicitly point to any
18 of the memory spaces of the 8051. In addition to the explicit pointers, the
19 compiler also allows a _generic class of pointers which can be used to point
20 to any of the memory spaces. 
21 <P>Pointer declaration examples.
22 <P>
23 <PRE>
24 /* pointer physically in xternal ram pointing to object in internal ram
25  */ 
26 data unsigned char * xdata p;
27 /* pointer physically in code rom pointing to data in xdata space */ 
28 xdata
29  unsigned char * code p;
30 /* pointer physically in code space pointing to data in code space */ 
31 code
32  unsigned char * code p;
33
34 /* the folowing is a generic pointer physically located
35  in xdata space */
36 char * xdata p;
37  
38 </PRE>
39 <P>Well you get the idea. For compatibility with the previous version of the
40 compiler, the following syntax for pointer declaration is also supported. Note
41 the above examples will be portable to other commercially available compilers.
42 <P>
43 <PRE>
44 unsigned char _xdata *ucxdp; /* pointer to data in external ram */ 
45 unsigned
46  char _data  *ucdp ; /* pointer to data in internal ram */ 
47 unsigned char _code
48   *uccp ; /* pointer to data in R/O code space */
49 unsigned char _idata *uccp;
50   /* pointer to upper 128 bytes of ram */
51  
52 </PRE>
53 <P>All unqualified pointers are treated as 3 - byte '_generic' pointers. These
54 type of pointers can also to be explicitly declared.
55 <P>
56 <PRE>
57 unsigned char _generic *ucgp;
58  
59 </PRE>
60 <P>The highest order byte of the generic pointers contains the data space
61 information. Assembler support routines are called whenever data is stored
62 or retrieved using _generic pointers. These are useful for developing reusable
63 library routines. Explicitly specifying the pointer type will generate the
64 most efficient code. Pointers declared using a mixture of OLD/NEW style could
65 have unpredictable results.
66 <HR>
67 <A HREF="SDCCUdoc-8.html">Next</A>
68 <A HREF="SDCCUdoc-6.html">Previous</A>
69 <A HREF="SDCCUdoc.html#toc7">Contents</A>
70 </BODY>
71 </HTML>