On May 10, 3:33=A0am, Jack Klein <jackkl...@[EMAIL PROTECTED]
> wrote:
> On Thu, 8 May 2008 02:20:26 -0500 (CDT), Vickynathan
> <ragunat...@[EMAIL PROTECTED]
> wrote in comp.lang.c.moderated:
>
> > The following code snippet works. I wonder how ? ( this is a code for
> > microcontroller )
>
> > void main (void){
>
> Before anyone else mentions it, since this is a free-standing
> implementation, void main() is not necessarily undefined behavior, and
> in fact is this particular implementation's normal entry point. =A0In
> small embedded systems, there is nothing for main() to return to.
>
> > unsigned char xdata * data pwrite;
> > unsigned char code * =A0data pread;
>
> You realize, I hope, that the non-standard extra keywords "xdata",
> "data", =A0and "code" are specific to your compiler. =A0As it happens,
> they have no real impact on your question.
>
> > unsigned char test_array [16];
> > unsigned char temp;
> > ....
> > ....
> > ....
>
> > pwrite =3D (unsigned char xdata *) Scratch_Flash_Addr ; =A0 =A0// I
have=
> > never seen such an initialization ??
>
> Leaving out the non-standard "xdata" and "data", which do not matter,
> what you have is:
>
> unsigned char *pwrite;
> pwrite =3D (unsigned char *)Scratch_Flash_Addr;
>
> Now you haven't shown us the definition of "Scratch_Flash_Addr", but I
> am going to assume that it is an integer type.
>
> C allows you to assign or initialize a pointer type with an integer
> type with a suitable cast, and here you are casting
> "Scratch_Flash_Addr" to the type of pwrite.
>
> The result of such a conversion is not guaranteed to be properly
> aligned or to point to anything you can access, but it does allow
> forming pointers to arbitrary areas of memory if you know what you are
> doing.
>
> > pread =3D my_array ;
>
> > .....
> > .....
>
> > for ( i=3D0; i< sizeof( my_array); i++ ){
> > .....
> > temp =3D pread[i]; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 //
Ho=
w is this possible
>
> If you do not understand that pointers can be used with subscripts,
> you really need to study some basic C. =A0You should also look at the
> FAQ for comp.lang.c and comp.lang.c.moderated, the link is in my
> signature block. =A0For starters, read all of section 6 about pointers
> and arrays.
>
> > without an indirection operator ?
> > .....
> > pwrite[i] =3D temp; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//
Ag=
ain no indirection
> > operator ??
> > .....
> > }
>
> In C, the expression symbol1 [symbol2] is always an indirection
> operation. =A0The language requires that this be translated as follows:
>
> First, if symbol1 is an array name, it is converted to a pointer to
> its first element.
>
> After this conversion, or if symbol1 was a pointer to start with, the
> expression is converted to *(symbol1 + symbol2).
>
> --
> Jack Klein
> Home:http://JK-Technology.Com
> FAQs for
> comp.lang.chttp://c-faq.com/
> comp.lang.c++http://www.para****ft.com/c++-faq-lite/
>
alt.comp.lang.learn.c-c++http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.ht=
ml
> --
> comp.lang.c.moderated - moderation address: c...@[EMAIL PROTECTED]
-- you
must
> have an appropriate newsgroups line in your header for your mail to be
see=
n,
> or the newsgroup name in square brackets in the subject line. =A0Sorry.
Hello Jack,
thanks for the tutorial on how to directly assign a memory address to
a declared pointer. That was my basic doubt. I sure will read through
the contents of the link that you gave.
Regards
Vickynathan
--
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.


|