Hi , I am working on LPC1788 with RTX , my code size is much bigger , so i want to optimize my code, after sarching through internet , there is optimization level(-O1 to -O3) specified by keil , but when i am using that optimization level(tried each level)in my code,but it is not working , not in debug mode also , why is this happened , please help or suggest.
Ok, so most likely a bug in your code, or some unsafe coding style/practices.
Make sure to use volatile variables where appropriate, this would be variables that change outside normal programming flow, and hardware peripheral registers that can read different values each time you read them.
Check also for uninitialized variables, and anything flagging warnings in your current code. Use #include files for all the library routines you use so it can check/verify the prototypes and calling routines.
The optimizer can change code order and fold code it perceives as doing nothing in the context it is used. Code may be moved out of loops, load constants instead of using math, etc.
Thanks for your reply, but my code is finely working without optimization , i just want to apply optimization level I am using keil5.23 and arm CC compiler version of 5.06 with FLASH FS but only after applying optimization level ,my code is not working, i have added necessary files ,still you think if any need to be add ,tell me that specific name for optimization level working.
>>but my code is finely working without optimization
Yes it might appear to, but I'm willing to believe there is a latent issue with your code over a bug in the compiler. The optimizer will not be tolerant of sloppy coding practices.
The compiler outputs "errors" where there are issues with syntax, it does not make a judgement about functional correctness.
>> i just want to apply optimization level Ok, then you might need to apply function level attributes or pragmas to control optimization, until you identify the code at issue. Use bisection to isolate the issue.
Thanks for reply,
>> Ok, then you might need to apply function level attributes or pragmas to control optimization, until you identify the code at issue. Use bisection to isolate the issue. I have used #pragma in my code but still it shows error like unrecognized variable(directive)#Pragma Now you tell me where i am wrong?
What do you mean, "like" ?
The compiler is telling you that it does not recognise what you've written - so go back to the documentation and check carefully for the correct usage, spelling, etc ...
Remember that 'C' is case-sensitive - so "pragma" is not the same as "Pragma" ...
If you still can't figure it out, post the complete message: copy and paste it; do not manually re-type it.
Also show the source line(s) to which it relates.
Follow the instructions for posting source code - they are immediately above the box where you type your message.
Why must everything be so laboured? I provide hints so I don't have to walk you down the path of discovery, or provide a check-list or script to follow.
www.keil.com/.../armcc_chr1359124988971.htm http://www.keil.com/support/docs/3704.htm www.keil.com/.../armcc_chr1359124989673.htm
What you're ultimately trying to determine is what part of your code is unsafe, where it is not sufficiently specific about the start conditions, or usage, where the optimizer applies the rules of C more rigorously, where you expect specific behaviour but have provided non-specific instructions or coded unspecified behaviour.
Thanks ,ok my mistake(spelling)nexttime onwards i will be carefull while posting error.
but i have used the same syntax as follows #pragma push #pragma OT(9) void function(void) {} #pragma pop
but still shows error below
error:TEST_REPORT_FILE_GENERATE_EXTRACT\test_report_file_generate_extract.c(477): warning: #161-D: unrecognized #pragma
Thanks for the link,but i have already gone through this link and only then i have used optimization function in my code.
now i dont understand where i am wrong thats why i posted my error ,if something i didn't trace ,where should i find the solution? ,thats why i am seeking guidance from you all.
thats why i have also share my working platform with you
Thanks much.
Follow the instructions for posting source code - they are immediately above the box where you type your message."
You didn't do that - did you?
Look at this picture to help you: www.danlhenry.com/.../keil_code.png