Page 1 of 1

Compiler optimization control

Posted: 12 Feb 2009 20:08
by Daniel Wee
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

Re: Compiler optimization control

Posted: 19 Mar 2009 10:53
by rajkovic
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.