This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Ye Ole Dereferenced Pointer Problem


Hi everyone!

I am writing code and compiling with a Hitachi SH7032 cross-compiler.  I
am attempting to write to external DRAM (as a memory test) and using the
following syntax:


(* (volatile unsigned char *)(0x09000001)) = 85;	/*dram address at
0x09000001 */
(* (volatile unsigned char *)(0x09000002)) = 85;	/*dram address at
0x09000002 */
(* (volatile unsigned char *)(0x09000003)) = 85;	/*dram address at
0x09000003 */
			   
This compiles fine and runs fine.  It writes 85 into each address
location.  But I really want to run this inside a 'for loop' such as
this...

for( int counter = 1; counter <= 3; counter++ ) 
{ 
	(* (volatile unsigned char *)(0x09000000 + counter) ) = 85;
}

The above compiles fine also but each time it gets to this point in the
code the SH7032 goes off into never never land.

Can anyone explain to me why the first section of code above works and
runs but the latter section of code causes some type of runtime error? 
Thanks so much.

BTW, a co-worker says I need parentheses around the whole thing except
the asterick such as...

*( (volatile unsigned char *)(0x09000000 + counter) ) = 85;

But that is odd since the it works without it fine as in the examples
above.

Robert F.

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]