Compiler optimization control

Post your requests and ideas on the future development of mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Daniel Wee
Posts: 38
Joined: 14 Jun 2007 22:05

Compiler optimization control

#1 Post by Daniel Wee » 12 Feb 2009 20:08

The mikroC for dsPIC compiler does some unused variable optimization in that if it thinks that a variable has been declared but unused, it will actually not compile for it. However, this can sometimes create problems. For example, take the following:-

unsigned char buffer;

void main(void)
{

asm {
mov _buffer, W0
inc W0, W0
mov W0, _buffer
}

while (1);
}

This is going to compile to an error because the pre-processor does not see the reference to the buffer variable in the asm block and so it will not compile for it. As such you will get a linking error which can be a little confusing because it doesn't really tell you what happened. When you look at the code, you cannot find anything wrong. To make this work right now, I have to include an explicit reference to the variable somewhere in the code in the non-asm section.

Is it possible to address this type of problems in the new compiler, or to have the option to turn off some optimizations?

Daniel

User avatar
rajkovic
mikroElektronika team
Posts: 694
Joined: 16 Aug 2004 12:40

Re: Compiler optimization control

#2 Post by rajkovic » 19 Mar 2009 10:53

Daniel Wee wrote:The mikroC for dsPIC compiler does some unused variable optimization in that if it thinks that a variable has been declared but unused, it will actually not compile for it. However, this can sometimes create problems. For example, take the following:-

unsigned char buffer;

void main(void)
{

asm {
mov _buffer, W0
inc W0, W0
mov W0, _buffer
}

while (1);
}

This is going to compile to an error because the pre-processor does not see the reference to the buffer variable in the asm block and so it will not compile for it. As such you will get a linking error which can be a little confusing because it doesn't really tell you what happened. When you look at the code, you cannot find anything wrong. To make this work right now, I have to include an explicit reference to the variable somewhere in the code in the non-asm section.

Is it possible to address this type of problems in the new compiler, or to have the option to turn off some optimizations?

Daniel
this will be implemented in next release of compiler. Already added to PRO PIC compiler.

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 Wish List”