This is the mail archive of the crossgcc@sourceware.cygnus.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


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

Re: Problem with too good optimization


   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


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