On Thu, 19 Jan 2012, Butuza Tamas wrote:

> Dear SDCC developers,
>
> I found a bug when I tried to compile a code for pic16F1938. (14 bit 
> enhanced core)
>
> The problem is: The optimizer breaks the code. Makes part of the code 
> unreachable.
> Error message is:
> test.c:51: warning 110: conditional flow changed by optimizer: so said EVELYN 
> the modified DOG
> test.c:52: warning 126: unreachable code
>
> The compiler has problem with this line in the interrupt routine: "if 
> ((irx1tmp & 0x01) != 0) {"
> Compiler thinks, the condition is always false, but it is not true.
> irx1tmp contains the received byte from serial port.

Actually, I think it's this condition that the compiler is issuing the 
warning about:

        if (doLedChange) {

The variable doLedChange is assigned an initial value of 0 in main() and 
never assigned a non-zero value in the while loop so the compiler 
concludes that this condition is always false. The compiler normally does 
not expect variables to spontaneously change their values. If you are 
doing something unusual such as an interrupt handler that changes the 
value of a variable that a non-interrupt hander is polling, you should use 
the "volatile" specifier to tell the compiler that the variable should not 
be optimized in any way:

   static volatile unsigned char irx1tmp, doLedChange, ledState;

(depending on what else you intend to do, irx1tmp and ledState may not 
need to be volatile and so might be better as a seperate declaration)

This is a much better approach than completely disabling all optimization
and is compatible with the ANSI/ISO C standards.

   Erik

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to