Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: Pointer ini...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 8 Topic 1096 of 1134
Post > Topic >>

Re: Pointer initialization and usage.

by Kenneth Brody <kenbrody@[EMAIL PROTECTED] > May 9, 2008 at 05:33 PM

Vickynathan wrote:
> 
> The following code snippet works. I wonder how ? ( this is a code for
> microcontroller )
> 
> void main (void){
> 
> unsigned char xdata * data pwrite;
> unsigned char code *  data pread;
> unsigned char test_array [16];
> unsigned char temp;
> ....
> ....
> ....
> 
> pwrite = (unsigned char xdata *) Scratch_Flash_Addr ;    // I have
> never seen such an initialization ??

You don't show the definition for Scratch_Flash_Addr, but given
your microcontroller comment, I will assume that it's some sort
of #define containing an address, such as:

    #define Scratch_Flash_Addr 0x8004

In order to treat this number as an address, you need to cast it
to a pointer, which is what "(unsigned char xdata *)" does.  It
tells the compiler to treat that number as a pointer to "unsigned
char xdata".  (I am also assuming that "xdata" is some compiler-
specific extension related to this microcontroller.)

> pread = my_array ;
> 
> .....
> .....
> 
> for ( i=0; i< sizeof( my_array); i++ ){
> .....
> temp = pread[i];                         // How is this possible
> without an indirection operator ?

The subscript is the "indirection operator".  Basically, an array
subscript such as "pread[i]" is the same as "*(pread+i)".

> .....
> pwrite[i] = temp;                        // Again no indirection
> operator ??

Ditto.

> .....
> }


-- 
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody        | www.hvcomputer.com | #include              |
| kenbrody/at\spamcop.net | www.fptech.com     |    <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@[EMAIL PROTECTED]
>
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 8 Posts in Topic:
Pointer initialization and usage.
Vickynathan <ragunath7  2008-05-08 02:20:26 
Re: Pointer initialization and usage.
Francis Glassborow <fr  2008-05-09 17:33:03 
Re: Pointer initialization and usage.
Kenneth Brody <kenbrod  2008-05-09 17:33:05 
Re: Pointer initialization and usage.
Vickynathan <ragunath7  2008-05-13 01:06:11 
Re: Pointer initialization and usage.
=?ISO-8859-1?Q?Hans-Bernh  2008-05-09 17:33:09 
Re: Pointer initialization and usage.
Jack Klein <jackklein@  2008-05-09 17:33:14 
Re: Pointer initialization and usage.
Vickynathan <ragunath7  2008-05-13 01:06:17 
Re: Pointer initialization and usage.
Francis Glassborow <fr  2008-05-13 01:06:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:19:22 CDT 2008.