This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: Bug in loop optimize (TREE stage)


dewar@gnat.com (Robert Dewar) writes:

> <<  This is undefined behaviour. Since you haven't initialised variable p,
> the compiler is free to implement whatever it likes here. In particular,
> >>
> 
> Presumably with warnings switched on, you would have got the appropriate
> warning which would have saved you submitting the bogus example :-)

Which warnings ?

Why I have so different result if I change 0xffffffff to 0xfffffffe ?
Or
Why I have a right result if I change `volatile unsigned char *p' to
`volatile unsigned int *p' ?

So, I can only repeat:

volatile unsigned char * volatile p;
/*                       ^^^^^^^^
  I have added this keyword without any results in output.  */

volatile unsigned char i;

/* Compiler don't know anything about P because it's a `volatile'
   variable. IE any part of program can change P in any time
   (interrupts, hardware, etc...).
   Also, compiler must save P to it's memory location immediately
   after any modification of P. */

int main(void) {

   do {
   	i++;
   } while(p++<(unsigned char *)0xffffffff);
   
   return 0;
}


Denis.


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