How to Turn Off All Optimizations/Eliminate SP debug info incorrect warning/etc

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to Turn Off All Optimizations/Eliminate SP debug info incorrect warning/etc

Jump to solution
1,566 Views
YeOldeBDM
Contributor III
Hi. I am using CodeWarrior 3.1 for HCS12.
 
I am having some problems with promotions to longs, the way certain #define's are taken when their size is not specified, etc mysterious results when an unsigned char member of a structure is a multiplicand versus a standalone unsigned char, understanding what is implementation dependent and what is not, AND ALL THAT GOOD STUFF.
 
I am experimenting with various snippets of code, and all too often the optimizations are obfuscating what is observed in the debugger.
 
Is there a way to setup a project so that all optimization is turned off (just for that project) ?
 
If there is no way to localize the compiler settings to that one project, can someone explain to me how to turn off all the optimizations anyway?
 
Thanks
 
Labels (1)
Tags (1)
0 Kudos
1 Solution
694 Views
CrasyCat
Specialist III
Hello
The symptoms you are describing are not directly related to optimization but rather to ANSI C standard definition.
You say "promotions to longs, the way certain #defines are taken when their size is not specified".
Please remember that ANSI C standard defines that integral promotion rule apply for arithmetic operation which do not involve a long operand.
 
That means if you have an assignment as follows:
  myLong = myInt1*myInt2;
the expression myInt1*myInt2 will be evaluated on 16-bit and then signed extended to 32-bits.
 
To make sure the expression is evaluated on 32-bits, you have to cast one of the operands as a long.
This is done as follows:
  myLong = (long)myInt1*myInt2;
 
for operand defined as macro (in a define), just add the suffix L to the constant to make sure it is interpreted as  a long.
For example
#define myInt1     10L
 
If you really want to disable optimization proceed as follows:
   - Open the project in the IDE
   - Open the Target Settings dialog (Press ALT + F7)
   - Switch to "Compiler for HC12" panel
   - Click on the "Options" button
   - THere are a lot of optimization you can disable there. This will be taken only for the current project.
 
However note that some optimization cannot be disable at al.
I hope this helps.
 
CrasyCat

View solution in original post

0 Kudos
1 Reply
695 Views
CrasyCat
Specialist III
Hello
The symptoms you are describing are not directly related to optimization but rather to ANSI C standard definition.
You say "promotions to longs, the way certain #defines are taken when their size is not specified".
Please remember that ANSI C standard defines that integral promotion rule apply for arithmetic operation which do not involve a long operand.
 
That means if you have an assignment as follows:
  myLong = myInt1*myInt2;
the expression myInt1*myInt2 will be evaluated on 16-bit and then signed extended to 32-bits.
 
To make sure the expression is evaluated on 32-bits, you have to cast one of the operands as a long.
This is done as follows:
  myLong = (long)myInt1*myInt2;
 
for operand defined as macro (in a define), just add the suffix L to the constant to make sure it is interpreted as  a long.
For example
#define myInt1     10L
 
If you really want to disable optimization proceed as follows:
   - Open the project in the IDE
   - Open the Target Settings dialog (Press ALT + F7)
   - Switch to "Compiler for HC12" panel
   - Click on the "Options" button
   - THere are a lot of optimization you can disable there. This will be taken only for the current project.
 
However note that some optimization cannot be disable at al.
I hope this helps.
 
CrasyCat
0 Kudos