Keil Logo

C51: PREVENTING COMMON BLOCK OPTIMIZATION


Information in this article applies to:

  • C51 Version 6
  • C51 Version 7

QUESTION

We have written a custom implementation of the setjmp function to solve some problems in our application. We are also using the highest optimization level with Linker Code Packing and we have a problem. The compiler and linker optimize the setjmp function calls and this causes problems for our application.

Is there a way to exclude a part of our code from optimization?

ANSWER

Yes. You may specify a different optimization level for the routine that contains the setjmp call. For example:

#pragma SAVE           // save current optimization level
#pragma OPTIMIZE(7)    // disable function block optimization
void func (void)  {

}
#pragma RESTORE        // restore original optimization level

The SAVE and OPTIMIZE pragmas save the current configuration and change the optimizer level to 7. The RESTORE pragma restores the previous optimizer level. Use these around your functions that use setjmp and common block subroutine optmization will be disabled (for these functions).

Note: It is not enough to reduce the optimization level to 8, since the compiler (or linker) would still combine code sections with other functions that are translated with optimize level 9 or higher.

MORE INFORMATION

  • Refer to SAVE in the Cx51 User's Guide.
  • Refer to RESTORE in the Cx51 User's Guide.
  • Refer to OPTIMIZE in the Cx51 User's Guide.

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Monday, July 18, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.