Problem with too good optimization

Doug Evans dje@transmeta.com
Mon Nov 1 10:45:00 GMT 1999


   Date: Mon, 01 Nov 1999 19:04:43 +0100
   From: Kai Schaeffer <kschaeffer@schaeffer-apparatebau.de>

   I have a little Problem, with the optimization of the gcc (m68k, version
   2.8.1). I want to wait until a value of a variable changes. So I write
   something like that:

   char c;

   test()
   {
     c=1;
     while(c);
   }


   The changing of 'c' happens in an interrupt routine. If I turn the
   optimization with -O2 on, the compiler produces code like this:

	move.b c,%d0
   .L6:
	tst.b %d0
	jbne .L6

   Of course the programm doesn't notice the changing of the value of 'c'. Are
   there any arguments for a variable that the compiler doesn't use a register?

The canonical solution is to change

char c;

to

volatile char c;

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



More information about the crossgcc mailing list