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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
2,124 次查看
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
 
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,252 次查看
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 项奖励
回复
1 回复
1,253 次查看
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 项奖励
回复