C compiler: Minimize the impact of disabling a specific optimization

16-Oct-2024

Enabling and disabling optimizations for the complete project or one of its modules can have a significant impact on the entire project.

With the #pragma optimize instructions you can selectively enable or disable specific optimizations at the source level, and obtain more fine-tuned results.

  • #pragma optimize [flags] controls the level of optimization.
    The remainder of the source line is scanned for option characters, which are processed similarly to the flags of the -O command line option.
  • #pragma optimize restore ends a region optimized with #pragma optimize.
    This
    restores the state as it was before the corresponding #pragma optimize.
#pragma optimize Y
[code]
#pragma optimize restore

In the above example, the peephole optimization is turned off for the code between the #pragma optimize instructions.

#pragma optimize/optimize restore pairs can be nested.


Was this answer helpful?