On Thu, 8 May 2008 02:20:26 -0500 (CDT), Vickynathan
<ragunath73@[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. In
small embedded systems, there is nothing for main() to return to.
> unsigned char xdata * data pwrite;
> unsigned char code * data pread;
You realize, I hope, that the non-standard extra keywords "xdata",
"data", and "code" are specific to your compiler. As it happens,
they have no real impact on your question.
> unsigned char test_array [16];
> unsigned char temp;
> ....
> ....
> ....
>
> pwrite = (unsigned char xdata *) Scratch_Flash_Addr ; // 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 = (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 = my_array ;
>
> .....
> .....
>
> for ( i=0; i< sizeof( my_array); i++ ){
> .....
> temp = pread[i]; // How is this possible
If you do not understand that pointers can be used with subscripts,
you really need to study some basic C. You should also look at the
FAQ for comp.lang.c and comp.lang.c.moderated, the link is in my
signature block. For starters, read all of section 6 about pointers
and arrays.
> without an indirection operator ?
> .....
> pwrite[i] = temp; // Again no indirection
> operator ??
> .....
> }
In C, the expression symbol1 [symbol2] is always an indirection
operation. The 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.c http://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.html
--
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.


|