question about the mikroC

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
wenming
Posts: 5
Joined: 21 Oct 2014 14:53
Location: China

question about the mikroC

#1 Post by wenming » 20 Oct 2015 12:25

Hello, dear friends:
I am a user of mikroC PRO for PIC in China, I have a question about the compiler. In the output setting, there is a option for Optimization level,the scope is from Zero to Five. What level is the best choice? Because I find that sometimes I program the MCU, the code in my device is not normal, but after I change the Optimization level(from four to zero), maybe the code in my device is normal. But when I modify my code and then program, the code in my device is not normal again, I have to change the Optimization level again, maybe
the code is normal. I am very sure the code is correct in logic. I doubt that maybe the Optimization cause some problems, and maybe the complier option is not correct in my mikroC ,so I have to send a mail to you, Can anyone help me something? Thank you :)

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: question about the mikroC

#2 Post by janni » 20 Oct 2015 13:38

Besides the optimization level 0 (which does not mean no-optimization), there is usually no noticeable difference in optimizer performance. It's best to use the default optimization level (4), as for this level one may be pretty sure that mE did perform compiler tests. Same about users' feedback in finding compiler quirks and errors.

As for differing code behaviour after program changes, it's most frequently a sign of variable overwriting due to faulty variables declaration or code. Even small code change may produce completely different variables distribution in RAM and thus a problem may show up or disappear. It's possible that switching between 0 and other optimization levels may, for specific code, lead to similar effects.

wenming
Posts: 5
Joined: 21 Oct 2014 14:53
Location: China

Re: question about the mikroC

#3 Post by wenming » 21 Oct 2015 01:42

janni wrote:Besides the optimization level 0 (which does not mean no-optimization), there is usually no noticeable difference in optimizer performance. It's best to use the default optimization level (4), as for this level one may be pretty sure that mE did perform compiler tests. Same about users' feedback in finding compiler quirks and errors.

As for differing code behaviour after program changes, it's most frequently a sign of variable overwriting due to faulty variables declaration or code. Even small code change may produce completely different variables distribution in RAM and thus a problem may show up or disappear. It's possible that switching between 0 and other optimization levels may, for specific code, lead to similar effects.
Hello, you said that due to faulty variables declaration or code, but the code is compiled successfully,how do I check the code?thanks

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: question about the mikroC

#4 Post by janni » 21 Oct 2015 11:52

Compiler doesn't check index range in array access, for example, so code may compile but it still may overwrite variables following an array in RAM. There are many ways to produce faulty code that compiles :wink: .

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: question about the mikroC

#5 Post by Aleksandar.Mitrovic » 21 Oct 2015 16:02

Hi,

If you are switching Optimization level this can cause some changes in your code.
Since optimization will make some changes in your project due to the code size and save space in your memory for example.

Regards,
Aleksandar

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: question about the mikroC

#6 Post by Dany » 26 Nov 2015 16:08

janni wrote:There are many ways to produce faulty code that compiles :wink: .
There are (infinite) much more possibilities that the code is faulty than possibilities that it is correct. :o :shock: Additionally one can never prove the code is correct, only that it is "faulty" or in "no fault popped up yet" state.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

HiEveryone
Posts: 43
Joined: 30 Nov 2012 22:01

Re: question about the mikroC

#7 Post by HiEveryone » 27 Nov 2015 18:26

janni wrote:Besides the optimization level 0 (which does not mean no-optimization)
The optimization level 0 I've got with mikroC 6.0.0 can't even optimize trivial stuff like x*2, x % 2, x / 2
I think it means 0 optimization... :roll:

Post Reply

Return to “mikroC PRO for PIC General”